首页 > 解决方案 > 使用自定义字段重置 angular4 中的下拉值

问题描述

在将旧的 Angular 应用程序迁移到 Angular 4 时,我在 .js 文件自定义下拉菜单中遇到了这个问题

hps-dropdown model="studentRequest.CountryType" reset-id="countryResetId" 
is-required="false" options="countryOptions" reset- 
id="resetCountryRequestResetId">hps-dropdown

如何在 Angular 4 代码中使用 resetid:

     function setDefaultCountry() {
                var queryParams = $location.search();
                if (queryParams.Region) {
                   ---
                   ---
                    });
                    if (RegionsArray.length > 0) {
                        Code = selectedArray[0].id;
                        // Reset the id to reflect values in drop down
                        this.countryResetId = new Date();
                    }
                }
            }

如何在角度 4 中调用相同以保持相同但是当我开始实现使用普通组合框而不是上面的模板并绑定所需的选项时。调用国家信息时,rest-id 的用途是什么。

    <select class="form-control" id="country" name="country" (change)="onCountryChange($event.target.value)" [(ngModel)]="countrySelected" required>
                                    <option value='' disabled="disabled">select</option>
                                    <option *ngFor="let country of countryList">{{country.name}}</option>
    </select>

基本上首先将加载国家/地区,然后根据它加载州。

标签: angularangular4-formsangular4-router

解决方案


推荐阅读