Angular 2 and LeafLet Uncaught ReferenceError: <function> is not defined at HTMLButtonElement.onclick Angular 2 and LeafLet Uncaught ReferenceError: <function> is not defined at HTMLButtonElement.onclick typescript typescript

Angular 2 and LeafLet Uncaught ReferenceError: <function> is not defined at HTMLButtonElement.onclick


Do not use onclick as it's an HTML and the function you assign to onclick will be searched in global scope of javascript i-e inside <script> tags and this is no more the part of Angular2. So what you should try is something like below

import {Component} from '@angular/core';@Component({selector: 'dynamic-button',template: '<button type="button" (click)="test()">Raumplan</button>'})export class DynamicButton{public test(): void{alert("Hi. I am a test call");  }}

And then

let popUp = (this.myData[i])['displayName'] +'<br/><dynamic-button></dynamic-button>';


in angular2 you will bind the event like this:

let popUp = (this.myData[i])['displayName'] +    '<br/><button (click)="test">Raumplan</button>';

OR this:

let popUp = (this.myData[i])['displayName'] +    '<br/><button on-click="test">Raumplan</button>';


You can try using (click)="OpenList()"

<button (click)="OpenList()" type="button" class="btn-link btn-anchor">List</button>

Typescript function

OpenList() {   }