I have a problem displaying the data on my View can't display objects iterated on my array. on my console show all objects with no error but I can't display using ngFor
posts.coomponent.ts
import { Component, OnInit } from '@angular/core';
import {Pipe, PipeTransform} from '@angular/core';
import {PostService} from '../posts.service';
import {Post} from '../posts';
@Component({
selector: 'app-form-posts',
templateUrl: './form-posts.component.html',
styleUrls: ['./form-posts.component.css'],
providers: [PostService]
})
export class FormPostsComponent implements OnInit {
submitted = false;
posts: Post[] = [];
constructor(
private _pService: PostService,
) { }
ngOnInit() {
this.getAllPost();
}
getAllPost() {
this._pService.getAll().subscribe(
posts => {
this.posts = posts ;
console.log(this.posts);
}
);
}
onSave() {
this.submitted = true;
}
}
posts.service.ts
import { Injectable } from '@angular/core';
import {Http, Headers, Response, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/do';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class PostService {
base: string = 'http://localhost:3000/posts';
constructor(
private _http: Http,
) {}
getAll() {
return this._http.get(this.base)
.map((response => response.json()));
}
}
console results this on my view
<li *ngFor="let post of posts">{{post.categoria}}</li>
postsit's an array not an object