简体   繁体   中英

ng-option or ng-repeat cannot updated after change array

i used ng-option or ng-repeat and change value of array but not bind new values

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

and i change it to ng-option and does work

that's angular js code

$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("");
    };
    ....
    ....

If you are using ng-repeat the you should provide what value to bind as..

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

So in this case the value of t gets bind to the ng-model..If you are using ng-options then you should use 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>

I am assuming here that ActivityData contains name and code as property....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM