实现数据绑定首先要在input的上面添加name属性,否则是绑定不上的。
添加完成name属性后再在input上面添加ng-model=”绑定的变量”
<input class="form-control" #ipt1="ngModel" [(ngModel)]="name" placeholder="请输入账号" name="name" value="" id="name" required>
然后在对应的component中创建绑定的变量
export class LoginComponent implements OnInit {
private name:string;
constructor() { }
//使用这个属性的时候使用this.name
let namea=this.name;
}