javascript - 像 ng-repeat 一样更改变量名称但不重复?

标签 javascript angularjs angularjs-directive angularjs-scope

在我的应用程序中,说$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"

根据documentation

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/

相关文章:

javascript - 非 -"text/javascript"类型的 <script> 标签在下载时会阻止 DOMContentLoaded 吗?

javascript - 将 javascript 添加到 Rails 应用程序页面

javascript - 在 Angular 指令中的前后链接中打印属性

javascript - AngularJS 适当的事件与 parent 和 child 的指令出价

AngularJS:如何在链接函数中获取指令的名称?

javascript - 正则表达式 - 使用仅匹配数字的量词匹配字符范围

javascript - bool 类型不可分配给 Filter 函数中的类型 "team"

angularjs - 如何保护 Firebase 应用程序免受无限循环的影响?

html - angularjs:如何从 Controller 模型注入(inject) HTML 代码

javascript - 表单字段/占位符和值