angular2 动态添加input输入框【转】

export class TComponent {

   username: any;
   id: number = 1;
   login:any = [{"username": "username" + this.id,"password": "pwd" + this.id}];

   addInput() {
       var number = this.login.length + 1;
       this.login.push({"username": "username" + number, "password": "pwd" + number});
   }

   removeInput(item) {
       console.log(item);
       let i = this.login.indexOf(item);
       console.log(i);
       this.login.splice(i, 1);
   }

}
动态添加表单
{{ login | json }}

原文地址:https://my.oschina.net/u/2499632/blog/778603

你可能感兴趣的:(angular2 动态添加input输入框【转】)