Error trying to diff '[object Object]'. Only arrays and iterables are allowed but i dont see...

Discussão em 'Angular' iniciado por mryusuf, Janeiro 1, 2025.

  1. mryusuf

    mryusuf Guest

    I have been having this problem for the past week, I have searched everywhere but wasn't able to find a problem.

    My service

    private texst!: Posts[];


    public getPosts(): Observable<Posts[]>
    {

    return this.http.get<Posts[]>("http://localhost/projects/php_rest_api/api/post/read.php").pipe(map((data) => {
    return this.texst = data;
    }));
    }



    My Component, here i add the service and run the function to get the data from my database

    public test: Posts[] = [];]

    constructor(public postService: PostsService,
    private http: HttpClient) {}

    ngOnInit(): void {
    this.getPosts();
    }

    public getPosts()
    {
    this.postService.getPosts().subscribe((response) => {
    this.test = response;
    console.log(this.test);
    })
    }


    My html

    <div>
    <button (click)="getPosts()"></button>
    <div *ngFor="let test of test">
    {{test.title}}
    </div>
    </div>


    [​IMG]

    Continue reading...

Compartilhe esta Página