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

前端 未结 8 1056
猫巷女王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:51

    Angular-cli includes the assets folder in the build options by default. I got this issue when the name of my images had spaces or dashes. For example :

    • 'my-image-name.png' should be 'myImageName.png'
    • 'my image name.png' should be 'myImageName.png'

    If you put the image in the assets/img folder, then this line of code should work in your templates :

    My image name
    

    If the issue persist just check if your Angular-cli config file and be sure that your assets folder is added in the build options.

提交回复
热议问题