angular refresh select options



我想刷新选择B选项一旦选择A更改我怎么做这个?

//select A
<select (change)="fasechange()" name="" [(ngModel)]="fase" id="">
<option *ngFor="let item of arrayA">{{item.name}}</option>
</select>
//Select B
<select name="" [(ngModel)]="equipo1"  id="">
<option *ngFor="let item of arrayB">{{item}}</option>
</select>

和change function for select A

arrayB: Array<string> = [];
fasechange(){
for(let a of this.options){
if(a.name == this.fase){
this.arrayB.push(this.option.opt);
}
}
}

我需要更新,刷新选择B一旦更改功能结束,我怎么能做到这一点?谢谢你的帮助

你也可以使用ChangeDetectorRef来强制更新

fasechange(){
for(let a of this.options){
if(a.name == this.fase){
this.arrayB.push(this.option.opt);
this.changeDetector.detectChanges(); // Inject it in your component constructor
}
}
}

Push后,需要为arrayB创建新的引用

fasechange(){
for(let a of this.options){
if(a.name == this.fase){
this.arrayB.push(this.option.opt);
this.arrayB  = [...this.arrayB]
}
}
}

最新更新