I have personInvolved component. This component has personDetails component. There is a button in personInvolved component. Onclick of the button I need to append the personDetails on DOM. each time I click it should append the personDetails component. How can I achieve this.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Use *ngFor
:
<button (click)="addPerson()">Add person</button>
<person-details *ngFor="let person of persons" [person]="person"></person-details>
And in the component code:
persons: Array<Person> = [];
addPerson() {
this.persons.push(new Person());
}