【问题标题】:dropdown list generating country, state, city using ng-select使用 ng-select 生成国家、州、城市的下拉列表
【发布时间】:2020-08-27 21:40:38
【问题描述】:

您好,我正在尝试使用显示国家/地区和城市的下拉列表生成一个反应式表单。但是,在选择国家之前,州和城市下拉列表将被禁用。其中一旦选择国家,国家下拉列表将被启用,并且与该国家相关的国家将在国家下拉列表中生成。 (同样适用于州和市)。

问题 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>

【问题讨论】:

标签: javascript angularjs angular-ngselect


【解决方案1】:

试试这个:

//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 的其他属性。

【讨论】:

    猜你喜欢
    • 2017-10-20
    • 2011-01-21
    • 2013-06-28
    • 2011-01-07
    • 2017-08-27
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多