【问题标题】:Submit a form from a button outside of the form in Angular从Angular中表单外部的按钮提交表单
【发布时间】:2018-10-30 19:31:06
【问题描述】:

如何通过位于表单外部的按钮以编程方式在 Angular (2+) 中提交表单? 这应该是通过调用 Angular 组件中的函数的点击事件?

【问题讨论】:

标签: angular


【解决方案1】:

我使用这里显示的方法(来自:How to trigger Angular 2 form submit from component?

NgForm 的属性 ngSubmit 是 EventEmitter。所以在 组件中的此属性将触发提交。

您还需要使用 f 变量而不是 formElement 因为 f 正在引用 ngForm。

@ViewChild('f') 表单:NgForm;

form.ngSubmit.emit();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-03
    • 1970-01-01
    • 1970-01-01
    • 2013-08-06
    • 2020-01-18
    • 1970-01-01
    相关资源
    最近更新 更多