Angular 确认关于取消更改复选框值的警报

Angular 确认关于取消更改复选框值的警报,angular,Angular,项目={ buyerAccept:null, buyerIncludeInProgram:false }; 删除(){ 如果(!confirm('you sure?'))返回; 否则{ this.item.buyerAccept=this.item.buyerAccept==true?null:true; this.item.buyerIncludeInProgram=this.item.buyerAccept==true?null:false; } } 去除 您可以尝试使用此解决方案 使用(

项目={
buyerAccept:null,
buyerIncludeInProgram:false
};
删除(){
如果(!confirm('you sure?'))返回;
否则{
this.item.buyerAccept=this.item.buyerAccept==true?null:true;
this.item.buyerIncludeInProgram=this.item.buyerAccept==true?null:false;
}
}

去除

您可以尝试使用此解决方案

使用
(单击)
事件,而不是
(更改)
事件

app.component.html

<div class="pretty p-default m-1">
  <input id="removeItemCheckbox" type="checkbox" [ngModel]="item.buyerAccept" (click)="remove($event)" />
  <div class="state p-warning">
    <label>Remove</label>
  </div>
</div>

你能举一个关于你的问题的最小的,生殖的例子吗?
remove($event) {
    if (!confirm('Are you sure?')) {
        $event.stopPropagation();
        return false;
    }
    else {
        this.item.buyerAccept = this.item.buyerAccept === true ? null : true;
        this.item.buyerIncludeInProgram = this.item.buyerAccept === true ? null : false;
    }
}