Html 如何连接变量名AngularJS?
在HTML代码中连接变量名,如:Html 如何连接变量名AngularJS?,html,angularjs,Html,Angularjs,在HTML代码中连接变量名,如: app.controllercode $scope.name ='abc'; $scope.abc123 = response.data; <h1>{{name}}</h1> <h1>{{{{name}}123}}</h1> <!-- here i need value of abc123 --> HTMLcode $scope.name ='abc'; $scope.a
app.controller
code
$scope.name ='abc';
$scope.abc123 = response.data;
<h1>{{name}}</h1>
<h1>{{{{name}}123}}</h1> <!-- here i need value of abc123 -->
HTML
code
$scope.name ='abc';
$scope.abc123 = response.data;
<h1>{{name}}</h1>
<h1>{{{{name}}123}}</h1> <!-- here i need value of abc123 -->
{{name}
{{{{name}}123}}
您没有创建具有动态名称的变量;因此,应按如下方式访问
<h1>{{name}}</h1>
<h1>{{abc123}}</h1> //as $scope.abc123 is defined in controller
{{name}
{{abc123}}//as$scope.abc123是在控制器中定义的
您没有创建具有动态名称的变量;因此,应按如下方式访问
<h1>{{name}}</h1>
<h1>{{abc123}}</h1> //as $scope.abc123 is defined in controller
{{name}
{{abc123}}//as$scope.abc123是在控制器中定义的
双倍大括号不起作用,因为它试图将123
解释为数字,但您可以使用ng bind
和{..}
的组合来实现。像这样:
<pre ng-bind="{{name}}123"></pre>
双倍大括号不起作用,因为它试图将
123
解释为数字,但您可以使用ng bind
和{..}
的组合来实现。像这样:
<pre ng-bind="{{name}}123"></pre>
您可以使用以下语法使用控制器:
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>
名称值:{vm.Name+'123'}和动态值:{{vm[vm.Name+'123']}
您可以使用以下语法使用控制器:
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>
名称值:{vm.Name+'123'}和动态值:{{vm[vm.Name+'123']}
在这里
angular.module('myApp',[]);
函数myCtrl($scope){
$scope.model={};
$scope.name='abc'
$scope.name2='def'
}
{{name}123{{name2}
在这里
angular.module('myApp',[]);
函数myCtrl($scope){
$scope.model={};
$scope.name='abc'
$scope.name2='def'
}
{{name}123{{name2}
这能用吗?{{{{name}}123}你想连接并使用吗?{{abc123}}这只是一个变量名@Veerabhadraao不,不起作用了,起作用了吗?{{{{name}}123}你想连接并使用吗?{{abc123}}这只是一个变量名@Veerabhadraao不,不是working@gifpif这会有帮助的u@gifpif这将帮助你