当我提交表单时,我创建的函数 onSubmit() 没有被调用。我已经搜索过了,但其他答案主要是按钮在表单之外,而不是我的情况,也许我错过了一些东西。
HTML:
<form ng-submit="onSubmit()" [formGroup]="messageForm">
<fieldset>
<label for="name">Nome e Sobrenome</label>
<input type="text" name="name" id="name" required formControlName="name">
<label for="email">Email</label>
<input type="email" name="email" id="email" required>
<label for="tel">Telefone</label>
<input type="text" name="tel" id="tel" required>
</fieldset>
<fieldset>
<label for="message">Mensagem</label>
<textarea name="message" id="message" cols="30" rows="10" required></textarea>
<button type="submit">Enviar</button>
</fieldset>
</form>
组件.TS
export class ContatoComponent{
title="Entre em contato conosco";
messageForm = new FormGroup({
name: new FormControl(""),
email: new FormControl(""),
tel: new FormControl(""),
message: new FormControl("")
})
constructor() { }
onSubmit(){
console.log("oi")
}
}