你好,我是新的角2。我在一个小型项目中,我必须设置图像。 这是我app.component.ts如何在angular2中加载图像
`
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-hero',
templateUrl: './hero.component.html',
styleUrls: ['./hero.component.css']
})
export class HeroComponent implements OnInit {
fullImagePath: string;
constructor() {
this.fullImagePath = '/assets/imges/therealdealportfoliohero.jpg'
}
ngOnInit() {
}
}
`
和HTML是 `
<div class="row">
<div class="col-xs-12">
<img [src]="fullImagePath">
</div>
</div>
`
,但在这个过程中我有将所有图像声明为单独的变量,但我想要de克莱尔一个数组,并加载所有,并利用它们像`
<div class="row">
<div class="col-xs-12">
<img [src]="fullImagePath/(myImagename)">
</div>
</div>
`
你做得很好,我很欣赏它。但是我想作这样的事' this.path =” /资产/ IMGS。; ' –
我编辑它提供了一种不同的方法 – DGarvanski
哇,这是一个很棒的方法:) –