在 Angular 6 中使用 sweet alert 重置字段
Reset fields using sweet alert in Angular 6
点击重置后,弹出窗口会询问您是否要重置字段(已完成,因为字段数量很多)。
代码
在.html
<button type="button" class="btn btn-danger" (click)="showAlert()">Reset</button>
在.ts
declare var swal: any;
import * as $ from 'jquery';
showAlert() {
swal({
title: 'Are you sure?',
text: "you want to reset",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, Reset it!'
}).then(function(){
//what to do here
})
}
解决了
.then(()=> {
this.myMethod();
})
myMethod()
{
$('#Formid').trigger("reset");
}
从头部删除函数名称并使用单独的函数
点击重置后,弹出窗口会询问您是否要重置字段(已完成,因为字段数量很多)。
代码
在.html
<button type="button" class="btn btn-danger" (click)="showAlert()">Reset</button>
在.ts
declare var swal: any;
import * as $ from 'jquery';
showAlert() {
swal({
title: 'Are you sure?',
text: "you want to reset",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, Reset it!'
}).then(function(){
//what to do here
})
}
解决了
.then(()=> {
this.myMethod();
})
myMethod()
{
$('#Formid').trigger("reset");
}
从头部删除函数名称并使用单独的函数