我'm new to angular and I' m尝试ng-bootstrap单选按钮 . 当有人点击按钮时,sweetalert2打开,如果我取消sweetalert2,单击按钮设置为单击 . 但是模型和以前一样没有请求触发器 .
零件
modelChanged($event, obj) {
swal({
title: 'Are you sure?',
text: "You want to change the status of course?",
type: 'warning',
showCancelButton: true,
allowOutsideClick: false,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes',
cancelButtonText: 'No',
confirmButtonClass: 'btn btn-success ml-2',
cancelButtonClass: 'btn btn-danger mr-2',
buttonsStyling: false,
reverseButtons: true
}).then((result) => {
if (result.value) {
this.loading = true;
const body = new HttpParams().set('something', JSON.stringify(something));
this.http.post('http://someurl', body, {
headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded'),
}).subscribe(res => {
//some action
}, error => {
});
swal(
'Done',
'status changed successfully',
'success'
)
} else if (
// Read more about handling dismissals
result.dismiss === swal.DismissReason.cancel
) {
swal(
'Cancelled',
'Request has been cancelled',
'error'
)
}
})
}
HTML:
<div *ngFor="let obj of someJson;index as i;trackBy:userById">
<div class="btn-group btn-group-toggle" ngbRadioGroup name="radioBasic" [ngModel]="obj.status" (ngModelChange)="modelChanged($event,obj)">
<label ngbButtonLabel class="btn-primary">
<input ngbButton type="radio" [value]="true"> Left (pre-checked)
</label>
<label ngbButtonLabel class="btn-primary">
<input ngbButton type="radio" [value]="false"> Middle
</label>
</div>
</div>
obj.status返回true / false,并首先说明它是真的 . 现在,当我点击中,这是假的,而sweetalert来了并按下取消,按钮突出显示,不应该这样做 . 它应该回到左边,这是真的 . 请建议我做什么 .