You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 14表单报错:表单提交取消,因表单未关联 求助

Angular表单提交异常排查记录

前端表单代码

<form [formGroup]="User" (ngSubmit)="onSubmit()">
....
....
    <button mat-raised-button type="submit"  color="primary" [disabled]="!User.valid">Sign-up</button>
    <p>Already have an account?</p><button mat-raised-button  type="button" color="secondary" routerLink="/login">Log in</button>
</form>

组件对应处理代码

async onSubmit() {
     this.authService.signUp(this.User.value);
}

已尝试的无效解决方案

  • 为onSubmit方法添加$event参数并调用e.preventDefault(),问题未解决
  • 移除async修饰符,无任何效果
  • 移除表单的(ngSubmit)绑定,改为绑定按钮点击事件,依旧报错
  • 移除(ngSubmit)、将按钮类型改为button、修改点击事件方法名,选中主表单时仍会立即触发相同错误

内容的提问来源于stack exchange,提问作者bilpor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 22:44:52