-2

ngIf and click not working for dynamic html.

when load html using innerHtml then ngIf and click event not loading.

export class FillInBlanksComponent implements OnDestroy, OnInit {    

     question = '';
     editable = true;
     ngOnInit() {    

         question = '<span *ngIf="editable" name="answers['+incr+']" contenteditable="true" (click)="onclick()"> </span>';
     }
     onClick(){
         alert("clicked!!!!");
     }    
}

2 Answers2

1

The function you're calling is (click)="onclick()" but you've defined onClick().

Another thing is, you might want to DOM Sanitize the string else you'll get a warning. Please check this answer out on how to do that.

SiddAjmera
  • 38,129
  • 5
  • 72
  • 110
0

check you have done spelling mistake use (click)="onClick()"

you are using small c in your function call

Shubham Singh
  • 147
  • 1
  • 2
  • 15