angular - 从离子警报中的按钮触发 ngSubmit
问题描述
我已经构建了一个离子应用程序,并在 Angular 中使用模板驱动的表单来收集表单数据并用于ngSubmit
将数据传递到ts.file
. 我想ngSubmit
通过警报中的“否并保存数据”按钮触发功能,但我的警报功能与我的html.file
. 我不知道如何将数据传递给警报功能,要么ngSubmit
通过警报触发。
html.文件
<form #observeForm="ngForm" (ngSubmit)="onSubmit(observeForm.value)" [(observeForm.value)]="tester">
...
<ion-button margin-top="auto" expand="block" type="submit" routerDirection="backforward">Confirm</ion-button>
</form>
ts.文件
async presentAlertConfirm() {
const alert = await this.alertController.create({
header: 'Time Out!',
message: 'Do you want to add more observe time?',
buttons: [
{
text: 'Yes',
cssClass: 'secondary',
handler: () => {
this.startTimer();
console.log('Add time Okay');
}
},
{
text: 'No and save data',
role: 'cancel',
cssClass: 'secondary',
handler: (blah) => {
this.timer = 0;
}
}
]
});
await alert.present();
}
解决方案
尝试通过@ViewChild() 获取参考:
@ViewChild('observeForm') obsForm: any; // new line
async presentAlertConfirm() {
const alert = await this.alertController.create({
header: 'Time Out!',
message: 'Do you want to add more observe time?',
buttons: [
{
text: 'Yes',
cssClass: 'secondary',
handler: () => {
this.startTimer();
console.log('Add time Okay');
}
},
{
text: 'No and save data',
role: 'cancel',
cssClass: 'secondary',
handler: (blah) => {
this.obsForm.onSubmit(); // new line
this.timer = 0;
}
}
]
});
await alert.present();
}
推荐阅读
- ruby-on-rails - React On Rails SSR“TypeError:无法读取未定义的属性'原型'”
- python - VS Code 没有在提到的 conda 环境中运行 Python 文件
- react-native - 在 Touchable 中 React Native UI 组件包装
- android - Android NDK 构建 cmake 包含 .aar 库中包含的 .so 库
- azure - 具有条件的 Azure 逻辑应用
- google-cloud-platform - 在产品中发送 Google Cloud Text to Speech WAV 文件?
- maven - 使用 Maven 从工件下载工件
- yii2 - Yii 2 - 使用配置中的别名将供应商中的 mdm 扩展文件覆盖到扩展文件夹
- react-native - 复选框未根据状态值呈现
- python - 为什么熊猫数据框自动具有自动编号的第一列