I have a simple component with a button. The action handler for this button is written in component controller (.ts file) and when clicked alerts and logs.
<button (click)="handleClick($event)"></button>
in button.component.ts
handleClick($event) {
alert('');
}
This component works fine if included in page directly like so :
<app-button></app-button>
Now, I am trying to inject button component dynamically inside a placeholder. I need to do this as I need to inject multiple components to a placeholder dynamically( inside a for loop).
I have gone through the Angular docs. I have also read through a lot of articles on the web. - this , this and many more.
Issue:
I am able to inject the component successfully in the placeholder. However, when I click the button, I see that handleClick is not a function error. Why is the button click handler which has been defined in the button controller not being recognized.
Help me find the missing piece.
UPDATE: The issue was that action handlers of that component needs to be public as suggested by @CommercialSuicide in the comments. Thank you for all the answers and comments.