Working with select using AngularJS's ng-options

前端 未结 8 890
渐次进展
渐次进展 2020-11-22 08:30

I have read about it in other posts, but I couldn\'t figure it out.

I have an array,

$scope.items = [
   {ID: \'000001\', Title: \'Chicago\'},
   {ID         


        
8条回答
  •  暖寄归人
    2020-11-22 08:58

    It can be useful. Bindings do not always work.

    
    

    For example, you fill the options list source model from a REST service. A selected value was known before filling the list, and it was set. After executing the REST request with $http, the list option is done.

    But the selected option is not set. For unknown reasons AngularJS in shadow $digest executing does not bind selected as it should be. I have got to use jQuery to set the selected. It`s important! AngularJS, in shadow, adds the prefix to the value of the attr "value" for generated by ng-repeat options. For int it is "number:".

    $scope.issue.productId = productId;
    function activate() {
        $http.get('/product/list')
           .then(function (response) {
               $scope.products = response.data;
    
               if (productId) {
                   console.log("" + $("#product option").length);//for clarity
                   $timeout(function () {
                       console.log("" + $("#product option").length);//for clarity
                       $('#product').val('number:'+productId);
    
                   }, 200);
               }
           });
    }
    

提交回复
热议问题