Angular [(ngModel)]在其他事件触发后更改数据

我不是角度事件方面的专家,但这是我的问题。如果我运行下面的代码,我基本上是在用错误的信息更新后端,因为在触发togglePlatform()之前,item.their_platform不会改变。

模板:

<mat-checkbox (ngModelChange)="togglePlatform()" [(ngModel)]="item.their_platform"></mat-checkbox>

TS:

 togglePlatform(){
      //update backend with the new value for item.their_platform
  }

我已经通过在togglePlatform方法中使用超时解决了这个问题,尽管我希望有一个不同的事件,我可以将该方法绑定到在这个场景中更有意义的事件。

有没有更好的活动?这是使用mat-checkbox与使用香草Angular的副作用吗?

谢谢

转载请注明出处:http://www.wxmcsj.com/article/20230401/1815226.html