本地文件在angularjs 4中显示404错误

时间:2017-05-29 09:06:53

标签: javascript html css angular

我是角度4的新手;我使用npm install -g @angular/cli安装了。然后使用ng new my-app创建了一个新项目。

|-src
|  -app
|    app.component.css
|    app.component.html
|    app.component.spec.ts
|    app.component.ts
|    app.module.ts

src文件夹包含app文件夹,其中包含相应的上述css,ts,html文件。现在我在app文件夹中添加了一个图像

|-src
|  -app
|    app.component.css
|    app.component.html
|    app.component.spec.ts
|    app.component.ts
|    app.module.ts
|    image.jpg

问题是,当我在app.component.html中添加<img src="image.jpg">标记时,它在控制台中显示404错误。但是如果我在app.component.css中添加类似background: url('image.jpg');的样式,它就可以了。

有什么建议吗?谢谢。

2 个答案:

答案 0 :(得分:1)

您应将所有公共资源(例如图片)放在remote_conn.send("no ManagedElement=1,Transport=1,Bridge=0-26,Vlan={}\n ".format(i)) 文件夹

然后,您可以通过src/assets这样的html/css

来访问它们

文件结构应如下:

/assets/image.jpg

答案 1 :(得分:0)

您需要提供图像路径位置。你可以这样做:

Double

这样你就可以参考你的image.jpg文件了。