bishoe nb

bishoe nb

  • 1.4k
  • 393
  • 10.5k

Cannot find a differ supporting object ‘[object Object]’ of

May 6 2019 1:29 AM
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
 
using router 
 
 
 
 
services
  1. getdetails(id:number){  
  2.   this.http.get('http://localhost:1858/api/details/' + id).map((data: Response) =>{  
  3.     return data.json() as INewsModule[];  
  4.   
  5.   }).toPromise().then(x=>{  
  6.     this._detailsNews = x;  
  7.   });  
  8.   }  
component
  1. import { Component, OnInit } from '@angular/core';  
  2. import { NewsService } from '../../../serv/news.service';  
  3. import { ActivatedRoute } from '@angular/router';  
  4.   
  5. @Component({  
  6.   selector: 'app-details',  
  7.   templateUrl: './details.component.html',  
  8.   styleUrls: ['./details.component.scss'],  
  9.   providers:[NewsService]  
  10. })  
  11. export class DetailsComponent implements OnInit {  
  12.   
  13.   constructor(private _NewsService : NewsService,  
  14.     private _activeRoute: ActivatedRoute) { }  
  15.   
  16.   ngOnInit() {  
  17.     let id : number = this._activeRoute.snapshot.params['id'];  
  18.   
  19.     this._NewsService.getdetails(id);  
  20.   
  21.   }  
  22.   
  23. }
template
  1. <table class="table">    
  2.     <caption>List of users</caption>    
  3.     <thead>    
  4.       <tr>    
  5.         <th scope="col">#</th>    
  6.         <th scope="col">NameNews</th>    
  7.        </tr>    
  8.     </thead>    
  9.     <tbody>    
  10.       <tr *ngFor="let details of _NewsService._detailsNews">    
  11.           <th scope="col">  {{details.NameNews}}</th>    
  12.     
  13. {{details.TopicNews}}    
  14. {{details.DateNews}}  
  15.       </tr>  
  16.     </tbody>    
  17. </table> 

Answers (8)