Pass a function as an argument in an ng-template Angular

Discussão em 'Angular' iniciado por Joel Imbergamo, Janeiro 15, 2025.

  1. I have 4 buttons where I want them to do different actions but they all look the same with different images. So I've created an ng-template to render them. My idea was to pass the function that each one was going to call as a parameter in the ng-template but I can't find a way to do it.

    Here is my idea:

    <ng-template #tempalte let-icon=icon let-action=action let-alt=alt>
    <div (click)="action()">
    <img src={{icon}} alt={{alt}}>
    </div>
    </ng-template>


    Is what I am trying to do even possible? Or it's my logic wrong and I am making a mistake?

    Thanks a lot!

    Continue reading...

Compartilhe esta Página