Why can't I define inline functions inside Angular templates ? How else to do it?
This works fine if you just provide the expression you want Angular to evaluate. If you have a property on your component e.g. value
, you can just use the following:
<button class="btn btn-primary" (click)="value = 'hi'">
Click Me
</button>
Angular essentially just calls the code that you provide as if it were inside a function (that's a big simplification, but works for your purposes).