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
-
Hi Lexy and welcome to Stack Overflow. Can you please add a starting point in code and what you have tried yourself?Roy– Roy2022-07-19 08:54:31 +00:00Commented 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 downvotedFrancis G– Francis G2022-07-19 08:56:29 +00:00Commented Jul 19, 2022 at 8:56
-
Please provide enough code so others can better understand or reproduce the problem.Community– Community Bot2022-07-19 12:56:17 +00:00Commented Jul 19, 2022 at 12:56
-
Nevermind I actually solved the problem now - had to iterate through an array of objectsLexy Andrews– Lexy Andrews2022-07-20 09:07:36 +00:00Commented Jul 20, 2022 at 9:07
Add a comment
|
1 Answer
@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>