我在subscribe
中有一个数组,如this.Term
,如果我安慰,它看起来像
[Discount Condition:Array(3), Stay Consition:Array(2)]
Discount Condition:Array(3)
0:object
EventType:"success"
Heading:"Discount Condition"
Help:"Terms"
1:object
EventType:"success"
Heading:"Discount Condition"
Help:"Terms"
2:object
0:object
EventType:"success"
Heading:"Discount Condition"
Help:"Terms"
Stay Condition:Array(2)
0:object
1:object
我试图在组件html中打印它,比如,
<div *ngFor="let item of Term">
{{item.Heading}}
</div>
如果我使用检查元素进行检查,则说明
<!--template bindings={
"ng-reflect-ng-for-of": ""
}-->
这是函数
getTerms(){
this.quoteService.getTerms()
.subscribe(
terms => {
this.terms = terms.resultData.Terms;
this.notes = terms.resultData.ImpNotes;
this.exclusions = terms.resultData.Exclusions;
var arr=[];
var strHeading;
for(let i=0;i<this.terms.length;i++) {
strHeading=this.terms[i].Heading;
if (arr.indexOf(strHeading) >= 0) {
this.uniqTerm[strHeading].push(this.terms[i]);
}
else {
if (!this.uniqTerm[strHeading])
this.uniqTerm[strHeading] = [];
this.uniqTerm[strHeading].push(this.terms[i]);
this.Term.push(this.uniqTerm);
arr.push(strHeading);
}
}
console.log(this.Term);
},
response => {
if (response.status == 404) {
//this.router.navigate(['NotFound']);
}
});
}
任何人都可以指出我哪里错了吗?
答案 0 :(得分:1)
this.Term
似乎是一个数组数组。
类似
<div *ngFor="let item of Term[0]">
{{item.Heading}}
</div>
将检查您的数据是否正确。
然后,如果你想迭代这些数组;
<div *ngFor="let item of Term">
<div *ngFor="let elem of item">
{{elem?.Heading}}
</div>
</div>
可能有用。