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