2

This question is from the open source project.

All images are stored in assets folder and the file is located in app/customer folder from where the code to load images is specified. The code is -

<img src="assets//images/{{customer.gender | lowercase}}.png" class="details-image" alt="">

The folder structure is -

-app
 -customer
  -fileLocation
-assets
 -images
  -image1.png

The images load properly. My question is - 'How the images are loading even the files are located at different levels? I cannot see the settings anywhere.

6
  • 1
    "different levels" meaning? Commented Oct 14, 2018 at 7:42
  • The image is called from file which is located in app/customer and the image is located in assets folder which is at same level as app folder. But nothing is specified like go one level up, then assets folder ..... Commented Oct 14, 2018 at 7:44
  • 1
    @Aparna reason is simple Angular-cli knows about assets folder Commented Oct 14, 2018 at 8:07
  • Thanks Vikas. Angular knewed it, but I did not knew how the angular knew it? Commented Oct 14, 2018 at 8:09
  • 1
    @Vikas True.. :-) Commented Oct 14, 2018 at 8:17

1 Answer 1

2

if you are using angular6 you are customize your assets in angular.json file for angular4/5 you can .angular-cli.json

enter image description here In the screenshot you can see the path hierarchy for assets.


Also when you build your project ng build, then from the generated dist folder you can see the assets folder path relation to index.html file enter image description here

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

9 Comments

Yes, I can see this code specified in angular.json file. It means when I mention 'assets' the path will get mapped to 'src/assets'. Am I correct?
no, from the dist folder you can view this relative path
your app is just the index.html file since it a single-page-application. So index.html and 'assets` folder are at the same level. so the root-path ie / is folder containing index.html file. so anywhere in the application it should be either "/assets/<path to resource>" or ` "assets/<path to resource>"`
No, but dist folder is created after the build. I have not build the project.
when you do ng-serve then angular-cli creates something like dist in the memory not on disk for server the content fast for development purpose. Since it is in in-memory we don't see that
|

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.