I am trying to call a method on a click event using typescript string literal for angular 4
For example:
{value:
<a (click)=alert('Hi')>Hello</a>
}
but it doesn't call the click event.
Was wondering if anyone had suggestions to this? Thanks!
Join Stack Overflow to learn, share knowledge, and build your career.
I am trying to call a method on a click event using typescript string literal for angular 4
For example:
{value:
<a (click)=alert('Hi')>Hello</a>
}
but it doesn't call the click event.
Was wondering if anyone had suggestions to this? Thanks!
alert
or another global function in a template; you should call a public method of the component class. You could write:(click)="myMethod('Hi')"
, and callalert
inmyMethod
. See the Angular documentation. – ConnorsFan Dec 22 '17 at 3:22{value: ...}
. You should have only:<a (click)="myMethod('Hi')">Hello</a>
. – ConnorsFan Dec 22 '17 at 3:31