gpt4 book ai didi

angular - 从 Angular 表单外部的按钮提交表单

转载 作者:行者123 更新时间:2023-12-04 15:53:12 28 4
gpt4 key购买 nike

如何从位于表单外部的按钮以编程方式在 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com