I am trying to add Html by targeting an id. Html is showing but ngModel
and click are not working. How can I make it work?
app.component.html
<div id="myid">
</div>
app.component.ts
import { Component, ElementRef } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
mytext = "add something"
constructor(private myElement: ElementRef) {}
ngOnInit() {
this.addDiv()
}
pop(){
alert("hello")
}
addDiv(){
var div = document.createElement('div');
div.innerHTML = `<div>
<input type="text" [(ngModel)]="mytext">
<button type="button" class="btn (click)="pop()">Basic</button>
</div>`;
this.myElement.nativeElement.querySelector('#myid').append(div)
}
}