【发布时间】:2016-09-18 12:04:45
【问题描述】:
我想用角度做这样的事情,你怎么能这样做?
$scope.test = "foo";
$scope.foo = "bar";
在视野中
<span>{{scope[test]}}</span> <!-- and return $scope.foo that is "bar" -->
【问题讨论】:
标签: angularjs variables dynamic
我想用角度做这样的事情,你怎么能这样做?
$scope.test = "foo";
$scope.foo = "bar";
在视野中
<span>{{scope[test]}}</span> <!-- and return $scope.foo that is "bar" -->
【问题讨论】:
标签: angularjs variables dynamic
应该用括号表示:
<span>{{this[test]}}</span>
this 指向当前作用域对象,因此变量test 为“foo”,表达式将引用$scope.foo。
【讨论】: