Angular 2显示值来自可观察 [英] Angular 2 Display value from Observable
本文介绍了Angular 2显示值来自可观察的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想显示来自响应http的值,但是我不知道出了什么问题.
Hi I want display my value from response http but I don't know what is the problem.
http:
getAllApiContext(){
const options = this.getOptions("...");
return this.http
.get("jenkins/job/api_initialization/api/json", options)
.map((data: any) => {
return data.json().property[0].parameterDefinitions[1].choices;
})
}
她返回数组.
我的component.ts
My component.ts
context: Observable<Array<any>>;
ngOnInit() {
this.jenkinsJob.getAllApiContext().subscribe(data => {
this.context = data;
});
};
我的component.html
My component.html
<span *ngFor="let item of context | async">
<p>{{item}}</p>
</span>
推荐答案
删除ngFor
中的异步.由于您已经订阅了Observable,因此无需使用异步管道
remove the async in the ngFor
. since you are already subscribing to the observable, no need to use the async pipe
<span *ngFor="let item of context">
这篇关于Angular 2显示值来自可观察的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文