【发布时间】:2020-06-21 09:51:55
【问题描述】:
我有这段代码,但 Angular 无法加载图像。图像源和列表组件是 app 文件夹的子文件夹。 list.component.ts:
@Component({
selector: "app-list",
templateUrl: "./list.component.html",
styleUrls: ["./list.component.css"]
})
export class ListComponent{
posts = [
{title: "Hello" ,path: "../img/9ed86f4d59363daf10f67d41282cab6b.jpg"},
{title: "world", path: "C:\Users\iglij\Desktop\test\webapp\src\app\img\download.jpg"},
{title: "hi" ,path: "C:\Users\iglij\Desktop\test\webapp\src\app\img\img_girl.jpg"},
{title: "from" ,path: "C:\Users\iglij\Desktop\test\webapp\src\app\img\photo-1494548162494-384bba4ab999.jpg"},
{title: "there" ,path: "C:\Users\iglij\Desktop\test\webapp\src\app\img\photo-1535332371349-a5d229f49cb5.jpg"}
] ;
}
list.component.html:
<div class="container" *ngFor="let post of posts">
<div class="holder">
<h3>{{post.title}}</h3>
<img [src]="post.path" width="500" height="600">
</div>
</div>
我尝试了两种方法,img 源仍然无法正常工作。
【问题讨论】:
标签: javascript angular typescript