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
  • 67,908
  • 69
  • 250
  • 347

1 Answers1

13

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
  • 32,186
  • 68
  • 222
  • 392
Maikel
  • 190
  • 1
  • 11