I have been experimenting with looping in Angular 2, using the following code snippet:
if (true) {
for ( var i = 0; i < 4; i++ ){
console.log("the value of i is : " + i);
}
} else {
console.log("in else part") ;
}
However, when I check the console, I notice that the value of i
always remains at 0
, indicating that this may not be the correct way to loop in Angular 2.
I then attempted the following approach:
for ( let i = 0; i < 4; i++ ){
console.log("value : " + i) ;
}
Surprisingly, even with this change, the result remains consistent.
Could someone guide me on the right way to loop or iterate in Angular 2?