你好,我是新的角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
哇,這是一個很棒的方法:) –