不知道这是你的意思,但你可以创建一个服务来获取所需的数据(从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
});