我最近从Angular 1切换到Angular 4,现在很多事情对我来说似乎都是新的.其中一个似乎与数据绑定有关.在旧版本中,我会在JS控制器中将数组声明为$ scope.arrname,然后我可以使用ng-repeat在HTML视图中对其进行导航.
现在,当我试图获得相同的结果时,它只能部分起作用.我究竟做错了什么?
示例:在组件中,我声明了一个测试数组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 Code Online (Sandbox Code Playgroud)
为什么我的代码不像以前那样迭代数组?我在这里错过了什么?
Saj*_*ran 29
你应该使用ngFor而不是ng-repeat
<ol>
<li *ngFor="let item of testarr">{{item}}ITEM Found!</li>
</ol>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25091 次 |
| 最近记录: |