[英]How can I use a variable in a path? (angularjs)
I want to use a variable to acsess the array... how? 我想使用变量来访问数组...如何?
example: (HTML FILE // VAR variable_here) 示例:(HTML文件// VAR variable_here)
<div class="subject-box" ng-repeat="subj in tmc.schultage.variable_here">
I hope anyone can help me. 我希望有人能帮助我。
Calvin 加尔文
you can use Square brackets to pass value as an object key. 您可以使用方括号将值作为对象键传递。
<div ng-controller="MyCtrl">
<div class="subject-box" ng-repeat="subj in tmc.schultage[name]">
{{subj}}
</div>
</div>
var myApp = angular.module('myApp',[]);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope) {
$scope.name = 'someArray';
$scope.tmc = {
schultage : {
someArray : [1,2,3,4,5,6,7]
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.