0

I have workspace structure that looks like this:

src/
   app/
   asset/
       img1.png
       img2.png
       img3.png

... As you can see, app folder and asset folder are on same level. My index file is inside src folder also. I'm trying to load image inside my component but can't make it show and i get error all the time something like:

GET http://localhost:4200/asset/img1.png 404 (Not Found)

my html looks like this:

<img style="height: 395px; width: 360px;" src="asset/img1.png">

Any solution for path?

4
  • 1
    Folder name is asset or assets? Angular by default creates assets. Please check Commented May 14, 2018 at 12:46
  • That is fine ...I have angular assets folder, but I created asset folder for my use Commented May 14, 2018 at 12:49
  • You will have to add this new folder ("asset") to the "assets" array in the angular json config file. Anyway, is there any good reason to use a different folder, rather than the default defined by angular's team? Commented May 14, 2018 at 12:56
  • I managed to move "asset" folder under my default angular "image" folder and change path to image/asset/img1.png and now it is working great. Thanks Commented May 14, 2018 at 13:00

2 Answers 2

1

By default the name of folder for assets is assets. This is set in .angular-cli.json in apps->assets settings.

When you put your files there you should be able to link them exactly like you do: <img style="height: 395px; width: 360px;" src="assets/img1.png">

Sign up to request clarification or add additional context in comments.

2 Comments

That is fine ...I have angular assets folder by default, but I created asset folder for my use and put images inside
In that case just add it to configuration I mention in the first paragraph. However I would recommend to use assets folder. That one is for your use :-)
1

Add your folder in .angular-cli.json file like following.

All the custom files that are created out of src folder needs to be added here.

"apps": [{
    "root": "src",
    "outDir": "dist",
    "assets": [
        "assets",
        "asset" // <-- Like this
    ],
........
}]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.