Angular 4 Data Binding over ng-repeat

I recently switched to Angular 4 from Angular 1, and now there is a lot for me. One of them seems to be related to data binding. In the old version, I declared the array as $ scope.arrname in the JS controller, and I could navigate through it as HTML using ng-repeat.

Now, when I try to achieve the same result, it only works partially. What am I doing wrong?

Example: in the component, I declared a test array testarr: any [] = [1,2,3];

{{testarr}}
   > Prints 1,2,3 on the scrreen 


<ol>
  <li ng-repeat="item in testarr">{{item}}ITEM Found!</li>
</ol>


>only iterates 1 time (ignoring the 2,3) in the array.
Run codeHide result

Why does my code not iterate over the array, as it was before? What am I missing here?

+6
source share
1 answer

You should use instead ngFor ng-repeat

<ol>
  <li *ngFor="let item of testarr">{{item}}ITEM Found!</li>
</ol>
+16
source

All Articles