1

I created service and component for listing objects in Angular. And list is working corretcly (I tried with 'console.log()'). But nothing appears when I try to print them in localhost:4200.

<table>
  <tr *ngFor="let py of list">
    <td>{{py.name}}</td>
  </tr>
</table>

("list" is an object array created with http get)

Also, my html component works fine, so it works when I write simple lines with <h1></h1>. And my object is not empty so if I change {{py.name}} part to {{py}}, I can see [object Object] in localhost. Can you help me to solve my problem?

I'm using vs code as IDE and here is my Angular version and ect:

Angular CLI: 12.1.1

Node: 14.17.3

Package Manager: npm 6.14.13

OS: win32 x64

0

1 Answer 1

3

Maybe you're console.loging at a point when the object is undefined.

To see the object's value in the HTML, you can take advantage of the json pipe.

Try this in your HTML:

<pre>{{ list | json }}</pre>

Also, you can't use *ngFor for an object I don't think, you usually use *ngFor for an array.

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

4 Comments

Thank you for your answer. I forgot to mention but list is an object array.
I used json and I can see my object's all values. But I need to print only name of the object.
Ok, your HTML seems fine to just print the name. It doesn't work?
I solve the problem. Problem was just discrepancy between database column names and angular model variable names. I didn't think about this simple case..

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.