AngularJs - ng-model in a SELECT

后端 未结 6 1105
执念已碎
执念已碎 2020-12-23 15:58

JSfiddle

Problem:

I have a SELECT-element in my page, which is filled in with an ng-repeat. It also has a ng-model

6条回答
  •  春和景丽
    2020-12-23 16:46

    However, ngOptions provides some benefits such as reducing memory and increasing speed by not creating a new scope for each repeated instance. angular docs

    Alternative solution is use ng-init directive. You can specify function that will be initialize your default data.

    $scope.init = function(){
                angular.forEach($scope.units, function(item){
                    if(item.id === $scope.data.unit){
                        $scope.data.unit = item;
                    }
                });
            } 
    

    See jsfiddle

提交回复
热议问题