表单的一般完整写法:
如果表单验证失败,必须 disable 提交按钮,阻止用户提交不合法的数据。
提交表单后,与表单对应的 json 数据 post 到后端:
{
"id":1,
"name":"pikachu",
"type":"fire"
}
修改 HTML, pokemon-template-form.component.html:
<!-- 当类型为 submit 的按钮被点击后,此 handleSubmit 将运行 -->
<form #form="ngForm" (ngSubmit)="handleSubmit(form)">
Pokemon Name:
<input type="text" [(ngModel)]="pokemon.name" name="name" />
<label>
<input
type="radio"
name="isCool"
[value]=&#