0

I'm new to Angular. I do not quite understand how *ngFor works in angular. Apperantly, you can only use it if you iterate through an array of objects and not only for an array. For my project, I need to go through an array that contains some IDs. Depending on that ID I will apply a badge. Somehow it only works for one and not for multiple. I hope i explained it properly, ask for more information if it's not clear what I tried to explain. ids_pic

4

1 Answer 1

1
@Component({/**/})
class MyComponent {
  public myArray: number[] = [11,12];
}

html:

<!-- ng-container for no html but with eaching -->
<ng-container *ngFor="let number of myArray"> 
  <div>{{number}}</div>
</ng-container>

or like this:

<!-- only one decorator with * per html block, for more when one - use ng-container -->
<div *ngFor="let number of myArray">{{number}}</div>
Sign up to request clarification or add additional context in comments.

Comments

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.