更改阵列后,ng-option或ng-repeat无法更新

时间:2016-06-05 05:56:15

标签: javascript angularjs

我使用ng-option或ng-repeat并更改数组的值但不绑定新值

<select multiple="true" ng-model="staticField.text">
    <option ng-repeat="t in Activitydata track by $index ">{{t}}</option>
</select>

我将其更改为ng-option并且可以正常工作

该角度js代码

$scope.Activitydata = [];
$scope.ActivityFound = function (from) {
    for (var h = 0; h < allRequestDetails.procurationCustomers.length; h++) {
        activitynote = allRequestDetails.procurationCustomers[h].notes;
        actList = activitynote.split('|');
        for (i = 0; i < actList.length; i++) {
            //alert(1);
            console.log('element : ' + actList[i]);
            $scope.Activitydata.push(actList[i]);
        }
        $scope.Activitydata.removeDuplicates();
        $scope.Activitydata.unique();
        $scope.Activitydata.remove("");
    };
    ....
    ....

1 个答案:

答案 0 :(得分:0)

如果您正在使用ng-repeat,则应提供要绑定的值...

<select multiple="true" ng-model="staticField.text">
<option ng-repeat="t in Activitydata track by $index" value={{t}}>{{t}}</option>

所以在这种情况下,t的值会绑定到ng-model ..如果你使用ng-options,那么你应该使用as ..

<select multiple="true" ng-model="staticField.text" ng-options="t.code as t.name for t in Activitydata track by $index ">
<option value="">Select</option>

我假设ActivityData包含名称代码作为属性....