如何解决角反应形式未连接
我有一个未连接的反应形式。无论我尝试什么,我总是在控制台中弹出此错误:由于未连接表单,因此取消了表单提交。
我在app.module.ts中导入了ReactiveFormsModule和FormsModule。
HTML:
<form [formGroup]="creationForm" (ngSubmit)="onSubmit()">
<div class="field-input">
<div>
<label for="name">Nom de l'agenda</label>
<input type="text" placeholder="Exemple : Dr Brassard" id="name" formControlName="name">
</div>
<div>
<label for="email">Email</label>
<input type="text" id="email" placeholder="Exemple : DrBrassard@gmail.com" formControlName="email">
</div>
<div>
<label for="tel">Téléphone fixe</label>
<input type="text" id="tel" placeholder="Exemple : 02 02 02 02 02" formControlName="tel">
</div>
<div>
<label for="mobile">Téléphone fixe</label>
<input type="text" id="mobile" placeholder="Exemple : 06 06 06 06 06" formControlName="mobile">
</div>
<div>
<label for="ctiId">Couplage CTI</label>
<input type="text" id="ctiId" placeholder="Optionnel" formControlName="ctiId">
</div>
<div>
<label for="password">Mot de passe</label>
<input type="password" id="password" placeholder="" formControlName="password">
</div>
</div>
<button type="button" class="btn btn-danger" [routerLink]="['/agendas']" routerLinkActive="active"
(click)="revert()" [disabled]="creationForm.pristine">Annuler</button>
<!-- <button type="button" class=" btn btn-primary" [disabled]="creationForm.invalid" [routerLink]="['/agendas']"
routerLinkActive="active">Finaliser</button> -->
<button type="submit" class="btn btn-success" [disabled]="creationForm.invalid" [routerLink]="['/wizard2']"
routerLinkActive="active">Suivant</button>
</form>
TS:
creationForm: FormGroup;
createFormGroup() {
return new FormGroup({
name: new FormControl('',[Validators.required,Validators.minLength(2)]),email: new FormControl('',Validators.email]),tel: new FormControl('',[Validators.required]),mobile: new FormControl(''),ctiId: new FormControl(''),password: new FormControl('',[Validators.required])
})
}
constructor() {
this.creationForm = this.createFormGroup();
}
onSubmit() {
console.log(this.creationForm);
}
我已经尝试过对每个按钮进行注释的几件事,除了一个按钮,左右移动这些东西,但是我看不出我做错了什么。
任何帮助表示赞赏。 干杯
解决方法
我从“提交”按钮中删除了路由器链接。必须将其包含在onSubmit()方法中。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。