角2:表单提交被取消,因为表单没有连接 [英] Angular 2: Form submission canceled because the form is not connected

查看:229
本文介绍了角2:表单提交被取消,因为表单没有连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


表单提交表单提交表单提交表单提交取消,因为表单没有连接

模式被添加到< modal-placeholder> code>元素,这是我的顶层元素< app-root> 的直接子元素。

从DOM中删除表单并在Angular 2中清除这个错误的正确方法是什么?我目前使用 componentRef.destroy();

解决方案

发生这种情况的其他原因,但在我的情况下,我有一个按钮被浏览器解释为提交按钮,因此当点击按钮导致错误时提交表单。添加type =button解决了问题。全部元素:

 < button type =button(click)=submitForm()> 


I have a modal that contains a form, when the modal is destroyed I get the following error in the console:

Form submission canceled because the form is not connected

The modal is added to a <modal-placeholder> element which is a direct child to <app-root>, my top level element.

What's the correct way to removing a form from the DOM and getting rid of this error in Angular 2? I currently use componentRef.destroy();

解决方案

There might be other reasons this occurs but in my case I had a button that was interpreted by the browser as a submit button and hence the form was submitted when the button was clicked causing the error. Adding type="button" fixed the issue. Full element:

    <button type="button" (click)="submitForm()">

这篇关于角2:表单提交被取消,因为表单没有连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆