不知道這是你的意思,但你可以創建一個服務來獲取所需的數據(從HTTP請求),
getData() : Observable<Model[]> {
// ...using get request
return this.http.get(this.url)
// ...and calling .json() on the response to return data
.map((res:Response) => res.json())
//...errors if any
.catch((error:any) => Observable.throw(error.json().error || 'Server error'));
}
和模型
export class Model {
constructor(
public id: string,
public imagePath: string
//other properties that you might need..
){}
}
那麼你只需要綁定src屬性,如
<img class="img-responsive" src="{{model.imagePath}}" style="max-height: 50px;"/>
請注意,您可以添加標題您的要求一樣,
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers }); // Create a request option
然後
return this.http.get(url, {
headers: headers
});