[英]Angular 2: String interpolation with function call
I am developing my first Angular app and having trouble with string interpolation.我正在开发我的第一个 Angular 应用程序,但在字符串插值方面遇到了问题。
I have a component which contains the following element:我有一个包含以下元素的组件:
`<span>{{action.getText()}}</span>`
action is of Type Action which has the following method: action 属于 Action 类型,它具有以下方法:
getText(): String { return "Test"; }
The variable action is defined correctly since I can access properties via {{}} without a problem.变量操作定义正确,因为我可以通过 {{}} 访问属性而没有问题。 eg {{action.title}}
例如{{action.title}}
So my question is, is this even possible to access this function and if yes, what am I doing wrong?所以我的问题是,这是否甚至可以访问此功能,如果是,我做错了什么?
You could convert it to a property:您可以将其转换为属性:
get text(): string { return "Test"; }
Your template becomes:您的模板变为:
<span>{{ation.text}}</span>
You refer to action.title
, but ation.getText()
.你指的是action.title
,但ation.getText()
。 Certainly a typo?肯定是打字错误?
<span>{{action.getText()}}</span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.