Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2: String interpolation with function call

I am developing my first Angular app and having trouble with string interpolation.

I have a component which contains the following element:

`<span>{{action.getText()}}</span>`

action is of Type Action which has the following method:

getText(): String { return "Test"; }

The variable action is defined correctly since I can access properties via {{}} without a problem. e.g. {{action.title}}

So my question is, is this even possible to access this function and if yes, what am I doing wrong?

like image 967
Luca Avatar asked Jun 01 '26 10:06

Luca


1 Answers

You could convert it to a property:

get text(): string { return "Test"; }

Your template becomes:

<span>{{ation.text}}</span>
like image 161
Cobus Kruger Avatar answered Jun 03 '26 00:06

Cobus Kruger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!