如何从位于表单外部的按钮以编程方式在 Angular (2+) 中提交表单? 这应该是通过点击事件调用 Angular 组件中的函数?
最佳答案
我使用这里显示的方法(来自:How to trigger Angular 2 form submit from component?)
NgForm has property ngSubmit which is EventEmitter. So doing emit() on this property from the component will trigger a submit.
Also you need to use your f variable instead of formElement because f is referencing to ngForm.
@ViewChild('f') form: NgForm;
form.ngSubmit.emit();
关于angular - 从 Angular 表单外部的按钮提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53060600/