根据来自另一个角度

时间:2018-08-02 13:24:13

标签: html angular

我有一个电话号码下拉列表,其中包含国家代码(印度+91)。基于此选择,国家下拉列表也应填充值。如果我在电话号码下拉列表中选择(印度+91),则在国家下拉列表中的值应更改为(印度)。我将国家/地区代码和国家/地区存储在json数组中。如何使用角度5做到这一点。

1 个答案:

答案 0 :(得分:0)

让我们说你有 html:

<select [(ngModel)]="code" (change)="onCodeChange($event)" >
<option *ngFor="let c of codeArr" [value]="c.id">{{c.value}}</option>
</select>
<select [(ngModel)]="country">
    <option *ngFor="let c of countryArr" [value]="c.id">{{c.value}}</option>
</select>

ts:

onCodeChange($event){
  this.country = $event.target.value;
}

我希望您能明白,更改代码下拉列表的值(id)时,您应该将值(id)分配给国家/地区下拉列表。