我的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
我该如何解决这个问题?
答案 0 :(得分:2)
在Angular 2中,您可以进行3种输入:
<msgfooter [errorType]="myCustomMessage"><msgfooter>
或
<msgfooter errorType="Invalid server"><msgfooter>
或
<msgfooter errorType="{{myCustomMessage}}">
将评估第一个,以便它在组件中查找特定变量(myCustomMessage
)。
第二个只传递一个字符串。
第三个将评估变量myCustomMessage
,对其进行字符串化并将其传递给errorType
输入。
您只能使用[]
或 {{}}
,但不能同时使用两者。