Is there a way to dynamically add a child component with each button click event?
Here is the HTML code for the button:
<button type="button" class="btn btn-success btn-sm btn-add-phone" (click)="addfield()"><span class="fa fa-plus"></span> </button>
The child component that gets displayed on every button click:
<app-farmer-registration-phone *ngIf="loadComponent"></app-farmer-registration-phone>
Corresponding Component TypeScript file:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-farmer-registration',
templateUrl: './farmer-registration.component.html',
styleUrls: ['./farmer-registration.component.css']
})
export class FarmerRegistrationComponent implements OnInit {
public loadComponent = false;
constructor() { }
ngOnInit() {
}
addfield(){
this.loadComponent = true;
}
}