How can I change the default favicon that is set by the Angular CLI?
I have tried many things, but it always shows the Angular logo as the favicon, even though I hav
For those needing a dynamically added favicon here is what I did with an app initializer:
import { APP_INITIALIZER, FactoryProvider } from '@angular/core'
export function faviconInitFactory () {
return () => {
const link: any = document.querySelector(`link[rel*='icon']`) || document.createElement('link')
link.type = 'image/x-icon'
link.rel = 'shortcut icon'
if (someExpression) {
link.href = 'url' || 'base64'
} else {
link.href = 'url' || 'base64'
}
document.getElementsByTagName('head')[ 0 ].appendChild(link)
}
}
export const FAVICON_INIT_PROVIDER: FactoryProvider = {
provide: APP_INITIALIZER,
multi: true,
useFactory: faviconInitFactory,
deps: []
}
Just remove fav.ico file under src/ and add this. The favicon will be added before app start
as simple and easy as :
that's done
I had the same issue, and solved it by forcing the refreshby the method described here:
To refresh your site's favicon you can force browsers to download a new version using the link tag and a querystring on your filename. This is especially helpful in production environments to make sure your users get the update.
<link rel="icon" href="http://www.yoursite.com/favicon.ico?v=2" />
Navigating to the file finally fixed this for me. In my case: http://localhost:4200/favicon.ico
I had tried to refresh, stop and start ng serve
again, and "Empty Cache and Hard Reload", none worked.
<link rel="icon" type="image/x-icon" href="#">
Add source of your icon and restart app it will change.
Ok, here in 2020 on 9.1.12. I don't understand why exactly this process is so difficult. I followed almost every post above and none of them worked for me.
What DID work was this: Totally removing the favicon reference in index.html. It's totally counter intuitive but it works. You DON'T need to put it in the assets
folder. I tried all of that but unfortunately none of those suggestions worked.
index.html
<!-- <link rel="icon" type="image/x-icon" href="favicon.ico"> DELETE THIS -->
angular.json
"assets": [
"src/favicon.ico",
"src/assets"
],
and when I run ng build --prod
, the favicon is there. Displays on my live server too.