您好,我正在尝试生成带有下拉列表的反应式表单,以显示国家/地区和城市。但是,在选择国家之前,“州和城市”下拉列表将被禁用。选择国家后,将启用州下拉列表,并在州下拉列表中生成与该国家有关的州。 (适用于州,然后适用于城市)。
Qn 1:如何禁用州和城市,直到选择了国家。
问题2:如何将州和城市绑定到第一个下拉列表?
谢谢!
国家/地区下拉列表的当前代码
<ng-select [clearable]="false" [items]="country" formControlName="countries" bindLabel="countryName" bindValue="countryCode" class="form-control">
<ng-template ng-option-tmp let-item="item">
<span title="{{item.name}}">{{item.name}}</span>
</ng-template>
</ng-select>
答案 0 :(得分:0)
尝试一下:
//Country dropdown
<ng-select #countryRef>
<ng-template ng-option-tmp let-item="item">
<span title="{{item.name}}">{{item.name}}</span>
</ng-template>
</ng-select>
//State dropdown
<ng-select [disabled]=['!countryRef.bindValue']>
<ng-template ng-option-tmp let-item="item">
<span title="{{item.name}}">{{item.name}}</span>
</ng-template>
</ng-select>
出于可读性考虑,我已删除了 ng-select 的其他属性。