使用 angular 2 显示图像 [英] Display image using angular 2

查看:27
本文介绍了使用 angular 2 显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 angular 2 很陌生我被困在这里我必须显示我使用相对路径的图像

I am very new to angular 2 I am stuck here where i have to display an image for which I'm using relative path­­­­­­­­­­­­­­­­­­­­

<img src="./../images/publicVideo1.PNG">

但出现以下错误

null:1 GET http://localhost:4200/null 404 (Not Found)

以上是我试图从 public-videos.component.html 访问的图像文件夹中的图像的应用程序结构

The above is the app structure where I have image in images folder which I'm trying to access from public-videos.component.html

我不明白我错在哪里任何帮助将不胜感激.

I dont understand where I'm wrong Any help would be appreciated.

推荐答案

在 src 目录中创建一个目录 assets.并将图像目录移动到资产中,然后您就可以像这样访问图像.在 app 文件夹中找不到图像,因为我们需要在 .angular-cli.json 中的 assets[] 块中设置路径.我们需要设置路径进入我们访问它的资产块.这有帮助吗.

create one dir assets in src directory. and move images directory into assets and then you can access image like that. image not found in app folder because we need to set path in assets[] block in the .angular-cli.json. we need set path into asset block we access it. does this help.

<img src="../../assets/images/publicVideo1.PNG">

angular-cli.json

这篇关于使用 angular 2 显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆