【发布时间】:2017-01-02 12:24:09
【问题描述】:
我需要添加一个静态图片,如下图。你能告诉我为什么我不能在主页上显示图片,如下图所示?即它不工作。
这里我用的是ASP.NET Core Template Pack
这是来自Steven Sanderson的不错的文章
\home\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)。可能是路径问题。我怎样才能正确给出它?图片如上所示。
【问题讨论】:
-
那么先生,您可以更容易地直接在 html src="" 中分配您的 url。你不需要 Angular 2 的帮助。但是如果您使用变量传递图像,则认为它是动态的,我认为您应该使用绝对路径。没有难受的感觉
-
但它不起作用,不是吗?可能是相对路径问题,不是吗? @AmitSuhag
-
你在使用 webpack 吗??使用绝对路径。相对路径将不起作用。您正在尝试从 ./
-
你可以在我的帖子上看到我的文件夹结构。请看。 @AmitSuhag
标签: angular webpack asp.net-core-mvc