Angular js,ng-change如何更新其他选择控件的选项

时间:2016-08-12 07:08:15

标签: javascript php jquery angularjs

在更改年份值时,我想更改Make下拉选项,但不知道如何更新其他控件的选项。

以下是我的形式的plunker。 https://plnkr.co/edit/aV65Nab9U9I6YlK2g4sY?p=preview
api.php是服务器响应,这些选项应显示在年份变化的Make下拉列表中。

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 个答案:

答案 0 :(得分: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>