Angular Refresh选择选项
选择一个更改后,我想刷新选择B选项 我该怎么做?
//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>
在选择A NED更新的更改函数中
arrayB: Array<string> = [];
fasechange(){
for(let a of this.options){
if(a.name == this.fase){
this.arrayB.push(this.option.opt);
}
}
}
,刷新选择b的变化功能结束,我该如何实现??? 感谢您的帮助
i want to refresh the select B options once select A change
how can i made this?
//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>
and in the 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);
}
}
}
i ned to update, refresh the select B onnce the change function ends, how can i make this happen???
thanks for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您也可以使用 changeTectorRef 强制更新。
You could also use ChangeDetectorRef to force the update.
按下后,您需要为ArrayB创建新的参考。
After Push, you need to create new reference for arrayB.
推动后,您需要重新创建数组参考(如此答案)也克隆对象。
因此,代码将是这样的:
或使用Lodash(或任何其他具有深克隆的公用事业库:
After push you need to recreate the array reference (as mentioned in this answer) but since you have array of objects, you need to clone the objects as well.
So the code would be something like this:
or with lodash (or any other utility library with deep cloning: