在角度,我可以将ng-repeat与ng-model结合起来吗?

时间:2015-03-05 05:26:08

标签: javascript angularjs

我希望该按钮的ng-modelng-repeat

相关
<a ng-repeat="x in [1,2,3,4]" ng-model="myButton[x]">{{myButton[x]}}</a>

控制器:

var id = 4;
$scope.myButton[id] = ' :( ';

我想创建一个名称是外部值组合的变量。此外,如果您有任何提示如何处理这样的事情,我将非常感激,因为我认为我正在以愚蠢的方式重新发明轮子。

1 个答案:

答案 0 :(得分:1)

Does this suit you?

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 ';
});