Iterate object inside object at Angular 8

Asked

Viewed 34 times

-3

would like to know if it is possible to display one object inside another at angle 8.

In case I have the property of the employee and within it has a department object with other properties.

I’d like to display the employee details and the name of the department he works in. But when using ngFor to iterate either it returns [Object Object] or returns blank field. And the employee has the registered department, po rme does not show on screen. Below the photos of the Employee and Department classes and the HTML page.

inserir a descrição da imagem aqui

1 answer

1

The solution is quite simple, really. The problem is that you are trying to print the object itself, which is not possible.

Just do it like this:

<th>{{ func.departamento.nome }}</th>
  • Hi Josemar, so when I put this way <th>{{ func.departmento.name }}</th> the field is blank on the screen, with no information.

  • 1

    Then the object has not been filled. Try to give a console.log to see if it is filled correctly or use a {{ func.departamento.nome | json }} to see directly in the template.

  • Really the object was empty. In the registration screen I had not put the property in [value], I had left as object. Thanks for the help Josemar.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.