2016-08-12 68 views
0

关于年份值的更改,我想更改Make下拉选项,但没有获取如何更新其他控件的选项。AngularJS,ng-change如何更新其他选择控件的选项

下面是我与形式plunker。 https://plnkr.co/edit/aV65Nab9U9I6YlK2g4sY?p=preview
api.php是服务器响应这些选项应显示在下拉菜单上的变化年。

autoQuoteCtrl.js

$scope.updateMakeList = function(){ 
} 

的index.html

<div class="row"> 
        <div class="form-group"> 
         <label class="col-sm-5 control-label" for="PC">{{questions[$state.current.name].VehicleYear.QuestionData._text}}</label> 
         <div class="col-sm-6"> 
          <select ng-change="updateMakeList" custom-required="true" ng-options="ans._value as ans._promptText for ans in questions[$state.current.name].VehicleYear.QuestionData._answerOptions" ng-model="answers.VehicleYear" ng-required="queObj._required" class="form-control {{queObj._pageAttributes.cssclass}}" name="{{questions[$state.current.name].VehicleYear.QuestionData._attributeName}}" id="{{questions[$state.current.name].VehicleYear.QuestionData._attributeName}}" data-que-obj="questions[$state.current.name].VehicleYear.QuestionData" select-control-dir setMake custom-required></select> 
         </div>      
        </div> 
        <span class="form-error" ng-show="submitted && DTOstep1.VehicleYear.$error.required">This field is required.</span> 
       </div> 

回答

1

你需要把这个功能在你的控制器 -

$scope.updateMakeList = function(name) 
        {     
// Your logic to change value in Make dropdown 
$scope.questions[name].VehicleMake.QuestionData._answerOptions = [{'_value':"test",'_promptText':"Test"}]; 
        } 

并更新HTML(年选择盒) -

  <div class="form-group"> 
       <label class="col-sm-5 control-label" for="PC">{{questions[$state.current.name].VehicleYear.QuestionData._text}}</label> 
       <div class="col-sm-6"> 
        <select ng-change="updateMakeList($state.current.name)" custom-required="true" ng-options="ans._value as ans._promptText for ans in questions[$state.current.name].VehicleYear.QuestionData._answerOptions" ng-model="answers.VehicleYear" ng-required="queObj._required" class="form-control {{queObj._pageAttributes.cssclass}}" name="{{questions[$state.current.name].VehicleYear.QuestionData._attributeName}}" id="{{questions[$state.current.name].VehicleYear.QuestionData._attributeName}}" data-que-obj="questions[$state.current.name].VehicleYear.QuestionData" select-control-dir setMake custom-required></select> 
       </div>      
      </div> 
相关问题