Estoy renderizando un botón basado en una cierta condición desde el backend. El botón se representa desde el archivo ts home.component.ts
if(backendLogic is true) { const buttonz = '<button onClick="xyz()"> Click me</button>'; return buttonz; } xyz() { console.log("haha"); }Ahora, al hacer clic en el botón, aparece un error que dice UncaughtReference: xyz no está definido. xyz() está presente en el mismo archivo mecanografiado. ¿Cómo llamo a esta función desde este elemento html? Estoy usando Angular.
Debe usar la directiva *ngIf:
componente.html:
<button *ngIf="backendLogic" onClick="xyz()">Click me</button>componente.ts:
xyz() { console.log("haha"); } Con este método, el botón solo se representará en el DOM cuando backendLogic sea true .