I am trying to display some data from server in my component.
export class CommerceComponent implements OnInit {
dealList;
ngOnInit() {
this.getDeals();
}
getDeals(){
this.gatewayService.searchDeals(this.searchParams).subscribe(
(data:any)=>{
this.dealList = data.result;
console.log("Deal list",this.dealList[0]);
},
(error)=>{
console.log("Error getting deal list",error);
}
);
}
Service
searchDeals(data){
var fd = new FormData();
fd.append('token',this.cookieService.get('token'));
fd.append('search',data.keyword);
return this.http.post(config.url+'hyperledger/queryByParams',fd);
}
In html
<div class="deal1" *ngFor="let deal of dealList">
{{deal.Deal.title}}
</div>
But the list is not rendering, however, I am getting console.log("Deal list",this.dealList[0]);
single object and this.dealList
return array of objects
If you get the result in this.dealList[0]
, you need also to iterate over [0]
indexed item.
<div class="deal1" *ngFor="let deal of dealList[0]">
{{deal.title}}
</div>
But your dealList
is undefined, so accessing [0]
will throw an exception. You need to initialize it as well
dealList = []
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.