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

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

问题描述

我对角度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.并将图像目录移到资产中,然后您可以像这样访问图像.在应用文件夹中找不到图片,因为我们需要在.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

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

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