Angular2 doesn't process HTML outside of a components template in any way, therefore it is expected (click)="processAdvise('BAJAJ-AUTO')
doesn't work.
onclick="processAdvise('BAJAJ-AUTO')"
also won't work when processAdvise()
is a method of an Angular2 component because onclick
is HTML-only and functions assigned this way are searched in the global JS scope not inside a components class.
<script>
tags are remove from Angular2 templates
@Component({
selector: '...',
....
})
class MyComponent {
constructor(private elRef:ElementRef) {
}
addHtml() {
// add the HTML to the DOM
this.elRef.nativeElement.querySelector('button').addEventListener('click', (event) => this.handleClick(event));
}
handleClick(event) {
// doSomething();
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…