Thursday, November 23, 2017

How do I get an image to show up in my Angular 4 app?

This is kinda tricky, huh? If you just make a folder somewhere then paths out to stuff in it will be interpreted as routes in the routing right? That won't do. If you look at angular-cli.json you will find a setting called assets that is probably also set to "assets" too. This setting defines a folder to be for images and hence an exception case for the routing rules. The folder (named "assets") needs to live inside the src folder but not a level deeper in the app folder. Look into it like so:

background-image: url("../../assets/GroverCleveland.png");

 
 

I hope everyone is having a Happy Thanksgiving.

No comments:

Post a Comment