Given a template like this:
给出这样的模板:
<li ng-repeat="user in users">
{{user.firstName}}
</li>
Is there any way to "alias" the "user" so I can do this instead:
有没有办法“别名”“用户”所以我可以这样做:
<li ng-repeat="SOME MAGIC HERE MAYBE?">
{{firstName}}
</li>
So that I don't need to type the "user." prefix for each expression?
这样我就不需要输入“用户”了。每个表达式的前缀?
1 个解决方案
#1
6
Here is the script to put into controller
这是放入控制器的脚本
$scope.scopify = function(scope, obj){
for (var a in obj) {
scope[a] = obj[a];
}
}
Then call it like this
然后这样称呼它
<li ng-repeat="user in users" ng-init="scopify(this,user)">
{{firstName}}
</li>
#1
6
Here is the script to put into controller
这是放入控制器的脚本
$scope.scopify = function(scope, obj){
for (var a in obj) {
scope[a] = obj[a];
}
}
Then call it like this
然后这样称呼它
<li ng-repeat="user in users" ng-init="scopify(this,user)">
{{firstName}}
</li>