在Angular 2上绑定自定义指令

时间:2016-06-08 14:10:24

标签: html angular

我的html页面上有自定义指令。对于我的组件msgfooter,我有不同的errorType消息:

<msgfooter [errorType]="Invalid server"> <msgfooter>

<msgfooter [errorType]="Few Parameters"> <msgfooter>

我通常在.ts文件上创建一个字符串。但在自定义指令中我不能这样做:

<msgfooter [errorType]={{myCustomMessage}}> <msgfooter>

错误:

Parser Error: Got interpolation ({{}}) where expression was expected at column 0

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

在Angular 2中,您可以进行3种输入:

<msgfooter [errorType]="myCustomMessage"><msgfooter>

<msgfooter errorType="Invalid server"><msgfooter>

<msgfooter errorType="{{myCustomMessage}}">

将评估第一个,以便它在组件中查找特定变量(myCustomMessage)。

第二个只传递一个字符串。

第三个将评估变量myCustomMessage,对其进行字符串化并将其传递给errorType输入。

您只能使用[] {{}},但不能同时使用两者。