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
  • Hi Lexy and welcome to Stack Overflow. Can you please add a starting point in code and what you have tried yourself? Commented Jul 19, 2022 at 8:54
  • Can you show and explain more details, Add a example data, code and/or image for visualization of your question, you will get downvoted Commented Jul 19, 2022 at 8:56
  • Please provide enough code so others can better understand or reproduce the problem. Commented Jul 19, 2022 at 12:56
  • Nevermind I actually solved the problem now - had to iterate through an array of objects Commented Jul 20, 2022 at 9:07

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.