3

I created a new Angular app with:

ng new ...

And I can view the application with:

ng serve --open

I removed the default src/favicon.ico and replaced it with src/favicon.png. I also opened src/index.html and changed the appropriate line to read:

<link rel="icon" type="image/png" href="favicon.png">

This doesn't seem to have worked. Issuing a GET request for /favicon.png simply returns the content from src/index.html. Restarting ng serve makes no difference.

How can I make this file accessible to the application?

Nathan Osman
  • 71,149
  • 71
  • 256
  • 361

1 Answers1

14

Make a PNG image with same name (i.e. favicon.png) and change the name in these files.

index.html

<link rel="icon" type="image/x-icon" href="favicon.png" />

angular.json

"assets": [
  "src/favicon.png" 
  "src/assets",
]

In older version of Angular (prior to v.7), the latter file is angular-cli.json

"assets": [
  "favicon.png" 
  "assets",
]

Afterwards, depending on browser, version OS etc.

  1. restart the app
  2. restart the browser
  3. clean cache
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
Maikel
  • 300
  • 2
  • 11