我有一个组件,它是一种具有窗体和其他一些变量的窗体。该组件是这样的:如何在Angular 2中将组件设置回初始状态
组件:
export class PersonComponent implements OnInit {
countPerson: number=0;
persons: Person [] = [];
personForm : FormGroup;
ngOnInit(){
this.step1Form= this.fb.group({
firstName: 'Levi',
lastName: 'Ackerman'
});
}
submitPerson(person: Person){
this.persons.push(person);
this.incrementPerson();
}
incrementPerson(){
this.count++;
}
}
在模板:
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body>
<label>First Name</label>
<input type="text" formControlName="firstName">
<label>LastName Name</label>
<input type="text" formControlName="lastName">
<button type="button" (click)="submitPerson()">Submit</button>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal">Close</button>
</div>
</div>
</div>
我想重置表单控件返回到初始值和以及设定外的变量的形式回到初始值。所以基本上我希望整个组件回到初始状态。我希望组件在关闭后重置为初始状态。
从哪里启动你的模态? – Aravind
模态由父组件触发。所以模态是一个子组件 – ilovejavaAJ
你是否想要在模态窗口中编辑人员数据? – Aravind