2017-12-12 11 views
1

からの値に応じて選択します。は、私は、次のように2枚のMD-の選択を持っている別の選択

<div layout=column> 
    <md-input-container flex><label for=organizations>Organization</label> 
      <md-select ng-model="dg.selectedOrganization" name=organizations aria-label="Organizations" required> 
        <md-option ng-value=organization ng-repeat="organization in dg.organizations"> {{organization.title}} </md-option> 
      </md-select> 
      <div ng-messages=dg.myForm.organizations.$error> 
        <div ng-messages-include=messages/messages.html></div> 
      </div> 
    </md-input-container> 
    <md-input-container flex><label for=rules>Role</label> 
      <md-select ng-model="dg.selectedRule" name=rules aria-label="Rules" required> 
        <md-option ng-value=rule ng-repeat="rule in dg.selectedOrganization.rules"> {{rule.title}} </md-option> 
      </md-select> 
      <div ng-messages=dg.myForm.rules.$error> 
        <div ng-messages-include=messages/messages.html></div> 
      </div> 
    </md-input-container> 
</div> 

私が最初にMD-選択(組織)から値を選択する際に、dg.selectedOrganizationが選択された値を取得し、選択された値に応じて2番目のmd-selectが設定されます。そして、私が2番目のmd-select(ルール)で何かを選択すると、dg.selectedRuleが選択された値を取得します。私はdg.selectedOrganizationを変更したときに、私が持っていた問題がある

私は新しいものを選択するまで、dg.selectedRuleはいつも私がdg.selectedOrganizationを変更した後、任意の値を選択する前に、通常dg.selectedRuleがnullである必要があり、古い値を持つことになります。

どうすればこの問題を解決できますか?

答えて

0

はdg.selectedOrganizationのためのonChangeハンドラを追加します。また、onChangeイベント火災、更新dg.selectedOrganization.rulesとはdg.selectedOrganization.rulesに存在する値にdg.selectedRuleを設定すると

を選択します。それを空の値に設定する場合は、selectに空の値があることを確認する必要があります。そうでない場合は、最初に使用可能なオプションに設定するだけです。

関連する問題