我想要的是:如果p1或p2被锁定,则所选选项保持不变; 但下面的代码工作不正确。所选的选项仍然改变。 有人可以给我一些建议吗?
<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;
答案 0 :(得分:1)
在 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();
}
这对我有用。我希望它也对您有用。
答案 1 :(得分:0)
我这样做的方式是
public class TidalBatchConsolidatedController : ApiController
{
public TidalBatchConsolidated GetAll(string id)
{
using (BDW_ProcessingEntities_TidalBatch entities = new BDW_ProcessingEntities_TidalBatch())
{
return entities.TidalBatchConsolidateds.FirstOrDefault(e => e.CompanyAbbr == id);
}
}
}
<mat-select [ngModel]="someProperty"
(selectionChange)="changeSelect($event)" ....>