0

I have an Angular2 component to display the list of speakers in some data. When I put the following code in my xyz.component.html, it displays the list as comma separated strings. How can I display each one in a different line -- essentially put a line break after every one.

<div *ngIf="data.speakers">
    <span class="attr-key">Speakers:</span><br>
    <span class="attr-value">{{data.speakers}}</span>
</div>

data is what comes due to binding. It has an element called speakers that is defined as string[].

1
  • 2
    can you list your data.speakers you need to use ngFor instead of ngIf Commented Aug 19, 2017 at 8:32

1 Answer 1

3

You need to use ngFor to loop over data and display it

<ul>
    <li *ngFor="let speaker of data.speakers">
      {{ speaker}}
    </li>
</ul>
Sign up to request clarification or add additional context in comments.

2 Comments

how do u know about the data ? atleast wait for the data :P
he is not quite sure of it i guess that is why i posted the comment

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.