1

This is my array which have property message which have another array.

chat = [{id:1, toUser:10, fromUser:11, seen:null, name:'Filip', messages:[{message:'Hello'},{message:'Hello again'}]}];

This is my HTML

<div *ngFor="let c of chat">
<h1>{{c.name}}</h1> //this works fine
<p>{{c.messages.message}}</p> //There I cant get anything. If I set c.messages[0].message I only get first result
</div>
0

1 Answer 1

1

Use a second nested ngFor. Something like:

<div *ngFor="let c of chat">
  <h1>{{c.name}}</h1>
  <p *ngFor="let item of c.messages">{{item.message}}</p>
</div>
Sign up to request clarification or add additional context in comments.

1 Comment

A good developer will check if c.messages is not null or undefined. you can use ng-container for that.

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.