gpt4 book ai didi

angular - 如何取消 Angular Material 2 中的 selectionChange 事件?

转载 作者:行者123 更新时间:2023-12-05 01:44:00 25 4
gpt4 key购买 nike

我想要的是:如果p1或p2被锁定,选择的选项保持不变;但是下面的代码不正确。所选选项仍然更改。谁能给我一些建议?

html

<mat-form-field style="text-align: center; width: 25%;">
<mat-select #singleSwap [(value)]="categoryProduct.sort"
(selectionChange)="singleSwapSelectionChange(singleSwap.value,categoryProduct.id)">
<mat-option *ngFor="let option of options" [value]="option">
{{ option }}
</mat-option>
</mat-select>
</mat-form-field>

组件

singleSwapSelectionChange(currentSelection: number, id: number) {
let p1 = this.categoryProducts.find(p => p.sort === currentSelection);
let p2 = this.categoryProducts.find(p => p.id === id);
if (p1.is_locked || p2.is_locked) {
console.log('locked!')
return;
}
p1.sort = p2.sort;
p2.sort = currentSelection;

最佳答案

html中发送事件:

(selectionChange)="asignarProcedure_reasing($event,$event.value,value.id)"

需要在ts的方法中接收事件:

asignarProcedure_reasing(e,user_id,procedure_id){

if(result.dismiss){

debugger;
e.source.writeValue(0);

// window.location.reload();
// this.ngOnInit();
}

这对我有用。我希望它也对你有用。

关于angular - 如何取消 Angular Material 2 中的 selectionChange 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47739305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com