如何使用模型的值作为角度js

时间:2015-12-04 19:40:20

标签: javascript angularjs

var myApp = angular.module('LoginApp',[]);

myApp.controller('dynamic', ['$scope', function($scope) {
   $scope.a_1= "Admin";

   $scope.auction_no = 1;

   $scope.item = [{ A:"a" , B:1 }];
}]);

我必须在{{x}}中以HTML格式提供模型名称,x应该是{{item.A}} _ {{auction_no}}。最后它应该给出输出Admin

2 个答案:

答案 0 :(得分:1)

您可以使用括号访问器$scope[$scope.item[0].A + "_" + $scope.auction_no]

答案 1 :(得分:0)

如果您能够将第一个变量作为对象:

$scope.auctions = {
  a_1: 'Admin'
};

$scope.auction_no = 1;
$scope.item = [{ A:"a" , B:1 }];

var x = $scope.auctions[$scope.item[0]['A'] + '_' + $scope.auction_no];

变量x此时应保留值Admin