Currently utilizing Angular framework
- My Add button triggers the appending of HTML content upon multiple clicks.
- The issue arises when I click the Add button, as the appended content fails to display textboxes or dropdowns. Instead, only the field names appear as plain text.
I would like to share my code snippet below:
TS
export class AppComponent {
name = 'Angular';
htmlToAdd : any ;
newHtml : any
constructor(private elementRef:ElementRef) {}
add(){
this.htmlToAdd = ` <form action="/action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form> `
}
}
HTML
<div class="one" [innerHtml]="htmlToAdd"></div>
<button (click)='add()'> Add </button>
<div [innerHtml]='newHtml'></div>