내 페이지에 2 개의 select
요소 가있는 다음 HTML이 있습니다. 둘 다 요구되기를 바랍니다. currentModel
첫 번째 요소 Year
가 기본값 인 이외의 값으로 선택 될 때까지 두 번째 요소 가 비활성화 된 상태로 유지 되기를 원합니다 .
<select class="form-control input-xsmall select-inline" data-ng-model="currentYear" >
<option>Year</option>
<option ng-repeat="year in years" value="{{year}}">{{year}}</option>
</select>
<select class="form-control input-xsmall select-inline" data-ng-model="currentModel">
<option>Model</option>
<option ng-repeat="model in models" value="{{model.niceName}}">{{model.name}}</option>
</select>
누군가가 이와 같은 선택 요소의 유효성을 검사하는 방법을 도와 줄 수 있습니까?
당신이 사용에 필요한 모든 및 NG-모델 ng-options
대신 수동으로 통해 옵션을 만드는 ng-repeat
. 앵귤러가 당신을 위해 옵션을 만들게하십시오.
<select class="form-control input-xsmall select-inline" data-ng-model="currentYear"
ng-options="year for year in years track by year">
<option value="">Year</option>
</select>
<select class="form-control input-xsmall select-inline" data-ng-model="currentModel"
ng-disabled="!currentYear"
ng-options ="model.niceName as model.name for model in models track by model.niceName">
<option value="">Model</option>
</select>
ng-options="year for year in years track by year"
구문을 따릅니다. label for value in array
ng-options ="model.niceName as model.name for model in models track by model.niceName"
구문을 따릅니다. select as label for value in array
ng-model
두 선택 모두 에 대해 설정하십시오 . select as
구문 ( model.niceName as model.name
)을 사용한 이후 모델 의 경우 선택한 항목의 속성 currentModel
이 있습니다 niceName
. select as
모델에서 부품 을 제거 하면 해당 모델 개체가 있습니다.
값에 따라 두 번째 선택에서 ng-disabled를 설정하십시오. currentModel
객체를 다룰 때 ng-select를 사용하는 버그 별 트랙이 있기 때문에 as
구문을 사용해야 합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다