Reputation: 719
This is the profile structure of my angular6 app:
Client.component.html is supposed to display the image "defaultProfilePic.png".
So it contains the following line of code:
<img [src]="url" width="220" height="200">
Client.component.ts contains the following line of code:
private url = "../asset/images/defaultProfilePic.png";
For some reason this doesn't work. Does anybody have any idea why that might be?
Upvotes: 0
Views: 8779
Reputation: 2408
That sound like your path isn't the correct one try by adding another ../
and make sure that you have the following setting in .angular-cli.json
"assets": [
"assets",
"favicon.ico"
],
Upvotes: 1
Reputation: 31
I found a way to show Angular static assets (.png in my case) in Stackblitz.
Upvotes: 1
Reputation: 12036
Yeah, the problem is you have created your own custom directory and you are trying to serve images from it.
you should use assets
folder to store your static assets, images etc.
if you want to store images and static assets in another directory you need to tell CLI about it by making an entry in assets
array of the angular.json file and you need to ensure that it is on the same level as the assets
folder. i.e create a custom folder under app
"assets": [
"src/favicon.ico",
"src/assets"
src/asset
],
Another mistake from your side is private url =
All
databound
properties must be typescriptpublic
property.why? Refer this
and you can provide absolute path instead of the relative path because CLI knows about it
public url = "asset/images/defaultProfilePic.png";
Upvotes: 5