0

The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?

 res : any[];
  constructor(http: HttpClient) { 
    http.get('http://jsonplaceholder.typicode.com/posts')
    .subscribe(response => {
      this.res = response;
    });
3
  • why do u even bother set a type if its any[]? it means nothing... Commented Apr 14, 2020 at 5:51
  • Btw, it's a pretty bad idea to use http stuff in the constructor. Do it in ngOnInit instead Commented Apr 14, 2020 at 5:53
  • It is giving error while assigning this.res = response Commented Apr 14, 2020 at 6:14

1 Answer 1

1

You are trying to assign object type response to array type, so you can push response to array like this.res.push(response);

Sign up to request clarification or add additional context in comments.

2 Comments

Errors are corrected.but i am not getting any output. if i am logging in console i get all the values. but when i am trying to display in list i am not getting the output values
@Mohammedzuhair : could you show how you read the list elements to display them?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.