我希望该按钮的ng-model
与ng-repeat
:
<a ng-repeat="x in [1,2,3,4]" ng-model="myButton[x]">{{myButton[x]}}</a>
控制器:
var id = 4;
$scope.myButton[id] = ' :( ';
我想创建一个名称是外部值组合的变量。此外,如果您有任何提示如何处理这样的事情,我将非常感激,因为我认为我正在以愚蠢的方式重新发明轮子。
答案 0 :(得分:1)
HTML:
<div ng-app="myApp" ng-controller="myCtrl">
<a ng-repeat="x in [1,2,3,4]" >{{myButton[x]}}</a>
</div>
JS:
var app = angular.module("myApp", []);
app.controller("myCtrl", function ($scope) {
var first = 1, forth = 4;
$scope.myButton = [];
$scope.myButton[first] = ' 1st ';
$scope.myButton[forth] = ' 4th ';
$scope.myButton[5] = ' 5th ';
});