在我的应用程序中,说$scope.item
。在我的页面中,我有一些模板将其引用为其他内容,例如 $scope.product
。
在一页上,我需要将模型引用为 item
,然后使用 ng-include
打开将其引用为 product
.
当数组中只有一项时,我执行了 ng-repeat="product in item"
。现在我用一个对象取消了单个数组,它只是一个对象。如果我执行ng-repeat
,它将对对象中的每个键/值对重复。这不是我想要的。
有没有办法说ng-alias="item as Product"
之类的?
最佳答案
ngInit 旨在用于别名。
ng-init="item = product"
The only appropriate use of ngInit is for aliasing special properties of ngRepeat, as seen in the demo below. Besides this case, you should use controllers rather than ngInit to initialize values on a scope.
关于javascript - 像 ng-repeat 一样更改变量名称但不重复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27851078/