Angular2中的数据绑定 墨蓝 2022-07-15 11:39 135阅读 0赞 实现数据绑定首先要在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; }
还没有评论,来说两句吧...