How to load image (and other assets) in Angular an project?

前端 未结 8 1070
猫巷女王i
猫巷女王i 2020-11-29 03:14

I\'m pretty new to Angular so I\'m not sure the best practice to do this.

I used angular-cli and ng new some-project to generate a new app.

In

8条回答
  •  甜味超标
    2020-11-29 03:54

    It is always dependent on where is your html file that refers to the path of the static resource (in this case the image).

    Example A:

    src
    |__assests
       |__images
          |__myimage.png
    |__yourmodule
       |__yourpage.html
    

    As you can see, yourpage.html is one folder away from the root (src folder), for this reason it needs one amount of ../ to go back to the root then you can walk to the image from root:

    
    

    Example B:

    src
    |__assests
       |__images
          |__myimage.png
    |__yourmodule
       |__yoursubmodule
          |__yourpage.html
    

    Here you have to go u in the tree by 2 folders:

    
    

提交回复
热议问题