0

I have created fake API using jsonplaceholder rendering into list. i got an output what i am expected but one compiler error as below i got output what i am expecting but one compiler error**

ERROR in src/app/posts/posts.component.ts:14:8 - error TS2696: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? Type 'Object' is missing the following properties from type 'any[]': length, pop, push, concat, and 26 more.

 14        this.posts = response;

This is my .ts

    import { Component, OnInit } from '@angular/core';
    import { HttpClient, HttpErrorResponse, HttpResponse } from '@angular/common/http';

    @Component({
      selector: 'posts',`enter code here
      templateUrl: './posts.component.html',
      styleUrls: ['./posts.component.css']
    })
    export class PostsComponent {
      posts : any[];
      constructor(private http:HttpClient) {
        http.get("http://jsonplaceholder.typicode.com/posts")
        .subscribe(response => { 
           this.posts = response;
          });
    }
    }

this is my template file

    <ul class="list-group">
        <li  
        *ngFor="let post of posts" 
        class="list-group-item">
            {{post.body}}
        </li>
    </ul>
M A Salman
  • 3,666
  • 2
  • 12
  • 26
  • https://stackoverflow.com/questions/47202177/angular-4-http-to-httpclient-property-someproperty-does-not-exist-on-type – M A Salman Mar 28 '20 at 11:10
  • Does this answer your question? [Angular 4 - Http to HttpClient - property 'someproperty' does not exist on type Object](https://stackoverflow.com/questions/47202177/angular-4-http-to-httpclient-property-someproperty-does-not-exist-on-type) – M A Salman Mar 28 '20 at 11:11

1 Answers1

1

Typescript is a typed language (but still compiled to js). So you propably didn't specified in service, what type of object you are getting in response (either in method header or .get<> generic type method). You shouldnt use any, but create your own class which will represent obkect structure you getting in response (or js object).

KamLar
  • 428
  • 4
  • 8