How to add div on every button click in angular6?

Programming Lover
Jun 13 · 1 min read

Here we are going to add a div(template) on a click event of a button, so in this whenever user click on that button then same div can be added every time.

For this we have to work mainly on two files html and typescript file.

In html file —

//Implemented a button
<button (click)=”addNewDiv()”>Add New Div</button>

//Created a div for calling again and again.
<div *ngFor=”let new_div of newDivs;”>

<p>This is a new Divisons</p>

</div>

In typescript file —

// Defining the adding div of array type
newDivs: addDivisions[] = [];

// function for adding div
addNewDiv() {
this.newDivs.push(new addDivisions())
}

// Here you can define the elements
export class addDivisions {

}