user3909296 user3909296 - 4 days ago 6
TypeScript Question

How can I pass a string literal to a method for a click event

I want to pass a string literal to a method for a click handler.

<button (click)="changeLanguage("en")">EN</button>


It does not work the way it is above. How can this be achieved?

Answer

You need single and double quotes:

<button (click)="changeLanguage('en')">EN</button>

proof it works:

yoloMcLogger(yolo)
{
   console.log(yolo)
}

<button (click)="yoloMcLogger('YOLO')">
    YOLO
</button>
Comments