ng-model is not getting changed in ui-select

后端 未结 9 688
太阳男子
太阳男子 2021-01-17 08:45

I\'m trying to achieve something very straightforward:


    {         


        
9条回答
  •  太阳男子
    2021-01-17 09:03

    I am having the similar issue for angularjs 1.4. In one controller ng-model value get update. But using the same way on other page it does not work. Following are my codes

    Working:

    var ctrl = this; 
    
    ctrl.filters = {};
    
    ctrl.filters.country = $rootScope.lUPro.RM_Country.split(",");
    
    $(".country_select2").select2().val(ctrl.filters.country).trigger('change');
    
    

    Select box is

    $comint->CountrySelectBox(array("name"=>"country[]",  "class"=>"country_select2 form-control",  "id" => "req_country",  "ng-model" => "ctrl.filters.country","multiple" =>"multiple")); 
    

    Not Working:

     var prectrl = this;
    
     prectrl.preferenceformdata = {};
    
      var pf = {};
    
      pf.country =  $rootScope.lUPro.RM_Country.split(",");
    
      prectrl.preferenceformdata = pf;
       $(".rm_country_select2").select2().val(prectrl.preferenceformdata.country).trigger('change');
    
    

    Select box:

    
     $comint->CountrySelectBox(array("name"=>"country[]","class"=>"country_select2 form-control","id" => "req_country","ng-model"=>"prectrl.preferenceformdata.country","multiple" =>"multiple"));
    
    

    So work around i am using to update value in ng-model variable:

    $(".country_select2").select2().val(prectrl.preferenceformdata.country)
    
    .trigger('change').on("change",
    
    function(e){
    
    var values = $(this).val();
    
    $scope.$apply(function(){prectrl.preferenceformdata.country = values;});
    
    });
    

提交回复
热议问题