All Projects → cloudnc → ngx-favicon

cloudnc / ngx-favicon

Licence: MIT license
Angular service to dynamically update the favicon on an app

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects
SCSS
7915 projects

Projects that are alternatives of or similar to ngx-favicon

favicon
Find a website's favicon.
Stars: ✭ 35 (+66.67%)
Mutual labels:  favicon, favicons
Icongenie
CLI tool to generate all the icons and splashscreens for your Quasar Apps
Stars: ✭ 174 (+728.57%)
Mutual labels:  favicon
Serve Favicon
favicon serving middleware
Stars: ✭ 586 (+2690.48%)
Mutual labels:  favicon
Redux Favicon
Redux middleware that displays colourful notification badges in the favicon area.
Stars: ✭ 103 (+390.48%)
Mutual labels:  favicon
Ultimate Metatags
A large snippet for your page's <head> that includes all the meta tags you'll need for OPTIMAL sharing and SEO. Extensive work has been put into ensuring you have the optimal images for the most important social media platforms.
Stars: ✭ 24 (+14.29%)
Mutual labels:  favicon
Customizer
Kanboard - Customizer adds GUI for logo, favicon and themes
Stars: ✭ 120 (+471.43%)
Mutual labels:  favicon
Besticon
Favicon service written in Go
Stars: ✭ 472 (+2147.62%)
Mutual labels:  favicon
Supercookie
💭 Inspiration
Stars: ✭ 3,630 (+17185.71%)
Mutual labels:  favicon
Faviator
A simple easy favicon generator.
Stars: ✭ 155 (+638.1%)
Mutual labels:  favicon
Faviconbar
A favicon based favourites bar for Safari
Stars: ✭ 84 (+300%)
Mutual labels:  favicon
Favicon Switcher
Make favicon react on media queries
Stars: ✭ 76 (+261.9%)
Mutual labels:  favicon
Favicons
Favicons generator for Node.js
Stars: ✭ 872 (+4052.38%)
Mutual labels:  favicon
Webapp Webpack Plugin
[DEPRECATED] use favicons-webpack-plugin instead
Stars: ✭ 127 (+504.76%)
Mutual labels:  favicon
Tools
Tools Online
Stars: ✭ 601 (+2761.9%)
Mutual labels:  favicon
Gatsby Plugin Favicon
Favicon Gatsby plugin
Stars: ✭ 175 (+733.33%)
Mutual labels:  favicon
Tinycon
A small library for manipulating the favicon, in particular adding alert bubbles and changing images.
Stars: ✭ 5,104 (+24204.76%)
Mutual labels:  favicon
Getfavicon
获取网站的Favicon图标并显示在你的网页上.
Stars: ✭ 45 (+114.29%)
Mutual labels:  favicon
Pwa Asset Generator
Automates PWA asset generation and image declaration. Automatically generates icon and splash screen images, favicons and mstile images. Updates manifest.json and index.html files with the generated images according to Web App Manifest specs and Apple Human Interface guidelines.
Stars: ✭ 1,787 (+8409.52%)
Mutual labels:  favicon
Favicon Emoji
🖼 Generate an emoji-favicon in your terminal
Stars: ✭ 247 (+1076.19%)
Mutual labels:  favicon
Rails Env Favicon
Gem to display the rails environment on the favicon
Stars: ✭ 212 (+909.52%)
Mutual labels:  favicon

NgxFaviconDemo

ngx-favicon demo

Setup

Install the library into your project:

npm i ngx-favicon

Put your favicon(s) somewhere into your project (/src for example) and don't forget to add them into angular.json file:

{
  ...
  "projects": {
    "[YOUR PROJECT NAME]": {
      ...
      "architect": {
        ...
        "build": {
          ...
          "options": {
            ...
            "assets": [
              "src/favicon.ico",
+             "src/favicon-success.ico",
+             "src/favicon-error.ico",
              "src/assets"
            ],
          }
        }
      }
    }
  }
}

Create a new file called (for example) favicon.config.ts and put into it the following code:

// enum all your different favicons
// (for type safety)
export enum CustomFavicon {
  FAVICON_SUCCESS = 'faviconSuccess',
  FAVICON_ERROR = 'faviconError',
}

export type AvailableCustomFavicons = { [key in CustomFavicon]: string };

// -------------------------------------------------------------
// @warning do not forget to add your favicons to your bundle
// you should double check into angular.json file
// -------------------------------------------------------------
// map all the types of favicon to their href
export const customFavicons: AvailableCustomFavicons = {
  // for some reason, impossible to use the syntax
  // [CustomFavicon.FAVICON_SUCCESS]: 'favicon-success.ico',
  // otherwise we end up with an AOT ERROR
  faviconSuccess: 'favicon-success.ico',
  faviconError: 'favicon-error.ico',
};

Open index.html file and add an ID to the link tag defining the favicon:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>NgxFaviconDemo</title>
    <base href="https://github.com/" />

    <meta name="viewport" content="width=device-width, initial-scale=1" />
-    <link rel="icon" type="image/x-icon" href="favicon.ico" />
+    <link id="favicon" rel="icon" type="image/x-icon" href="favicon.ico" />
  </head>
  <body>
    <app-root></app-root>
  </body>
</html>

Import the NgxFaviconModule with forRoot method and define your own config once only:

+ import { NgxFaviconModule } from 'ngx-favicon';
+ import { customFavicons, AvailableCustomFavicons } from './favicon.config';

@NgModule({
  ...
  imports: [
    ...
+   NgxFaviconModule.forRoot<AvailableCustomFavicons>({
+     faviconElementId: 'favicon',
+     defaultUrl: 'favicon.ico',
+     custom: customFavicons,
+   }),
  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

How to use it

Once everything is setup, you can inject the NgxFaviconService and use either the setDefaultFavicon, setCustomFavicon or setFaviconByUrl methods.

Example from a component:

.ts file:

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent {
+  public CustomFavicon: typeof CustomFavicon = CustomFavicon;

+  constructor(private ngxFaviconService: NgxFaviconService<CustomFavicon>) {}

+  public setDefaultFavicon(): void {
+    this.ngxFaviconService.setDefaultFavicon();
+  }

+  public setCustomFavicon(faviconName: CustomFavicon): void {
+    this.ngxFaviconService.setCustomFavicon(faviconName);
+  }

+  public setFaviconByUrl(faviconUrl: string): void {
+    this.ngxFaviconService.setFaviconByUrl(faviconUrl);
+  }
}

.html file:

+ <button (click)="setDefaultFavicon()" data-btn-default>Set default</button>
+ <button (click)="setCustomFavicon(CustomFavicon.FAVICON_SUCCESS)" data-btn-success>
+   Set success
+ </button>
+ <button (click)="setCustomFavicon(CustomFavicon.FAVICON_ERROR)" data-btn-error>
+   Set error
+ </button>
+ <button (click)="setFaviconByUrl('https://en.wikipedia.org/static/favicon/wikipedia.ico')" data-btn-url>
+   Set by URL
+ </button>

A complete example using the app is available in this repo, feel free to take a look into it (/src) and the source code of the library is located in /projects/ngx-favicon.

How to contribute

If you're willing to contribute to that project, feel free to do so.

  • Fork the project
  • Go into the repo and install dependencies by running yarn
  • Create a branch ex: git checkout -b /feat/my-feature or git checkout -b /fix/my-fix
  • Make some changes
  • Run yarn run prettier:write to make sure formatting is fine
  • Run yarn run lib:build:prod to build the library
  • Run yarn run demo:test to make sure all the tests are passing
  • Commit your changes using the Angular commit message conventions
  • Open a pull request

Thanks!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].