在HTML代码中连接变量名称,如:
app.controller
代码
$scope.name ='abc';
$scope.abc123 = response.data;
HTML
代码
<h1>{{name}}</h1>
<h1>{{{{name}}123}}</h1> <!-- here i need value of abc123 -->
答案 0 :(得分:2)
双倍花括号不起作用,因为它试图将123
解释为数字,但您可以使用ng-bind
和{{..}}
的组合来实现。像这样:
<pre ng-bind="{{name}}123"></pre>
以下是工作示例:
angular.module('myApp', []);
function myCtrl($scope) {
$scope.model = {};
$scope.name = 'abc'
$scope.abc123 = "test"
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp">
<div ng-controller="myCtrl">
<pre ng-bind="{{name}}123"></pre>
</div>
</body>
答案 1 :(得分:2)
您可以使用控制器作为语法:
var myApp = angular.module('myApp',[]);
myApp.controller("MyCtrl",MyCtrl);
function MyCtrl() {
this.name = 'abc';
this.abc123 = 'value';
}
vm.name+'123'
是动态密钥,然后从vm
<div ng-app="myApp" ng-controller="MyCtrl as vm" >
Name value: {{vm.name+'123'}} and dynamic value: {{vm[vm.name+'123']}}
</div>
答案 2 :(得分:1)
$scope.name ='abc';
$scope.abc123 = response.data;
您不是使用动态名称创建变量;因此应该按以下方式访问
<h1>{{name}}</h1>
<h1>{{abc123}}</h1> //as $scope.abc123 is defined in controller
答案 3 :(得分:1)
这是
aspect_ratio = bbox(1, 3) / bbox(1, 4);
&#13;
angular.module('myApp', []);
function myCtrl($scope) {
$scope.model = {};
$scope.name = 'abc'
$scope.name2 = 'def'
}
&#13;