我需要添加一个静态图像,如下所示。可以告诉我为什么我无法在主页上显示图像,如下所示?即它不工作。在ASP.NET Core + Angular 2上为Visual Studio设置图像路径
这里我使用这个ASP.NET Core Template Pack
下面是关于它的好文章,从Steven Sanderson
\家\ home.component.html
<img src="{{heroImageUrl}}" style="height:30px">
home.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'home',
template: require('./home.component.html')
})
export class HomeComponent {
public heroImageUrl ="./image/employee_management.jpg";
}
错误:
它说,像这样Failed to load resource: the server responded with a status of 404 (Not Found)
。可能是我issue.how可以给它正确的路径?图像如上所示。
那么先生,这很容易,你可以直接在html中分配你的url src =“”。你不需要角2帮助。但如果你使用变量传递图像认为它是动态的,我认为你应该使用绝对路径。没有硬的感觉 –
但它不工作不?可能是相对路径问题否? @AmitSuhag – Sampath
你使用的是webpack?使用绝对路径。相对路径将无法工作。您尝试从./ < - 这意味着您正在从当前目录进行检查。从/ app开始我猜不知道你的应用程序结构。为图片创建separte文件夹资源 –