Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 在Angular 2上绑定自定义指令_Html_Angular - Fatal编程技术网

Html 在Angular 2上绑定自定义指令

Html 在Angular 2上绑定自定义指令,html,angular,Html,Angular,我的html页面上有一个自定义指令。对于我的组件msgfooter,我有不同的errorType消息: <msgfooter [errorType]="Invalid server"> <msgfooter> 如何解决这个问题?在Angular 2中,您可以进行3种输入: <msgfooter [errorType]="myCustomMessage"><msgfooter> 或 或 将对第一个变量进行求值,以便它在组件中查找特定变

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

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

如何解决这个问题?

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

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



将对第一个变量进行求值,以便它在组件中查找特定变量(
myCustomMessage

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

第三个变量将计算变量
myCustomMessage
,将其字符串化并将其传递给
errorType
输入



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

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

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



将对第一个变量进行求值,以便它在组件中查找特定变量(
myCustomMessage

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

第三个变量将计算变量
myCustomMessage
,将其字符串化并将其传递给
errorType
输入



您只能同时使用
[]
{{}}

实际上,第三个仍然作为字符串使用,它不会计算变量。您基本上只是传递一个
{{myCustomMessage}
字符串值。第三个输入是
bind errorType=“myCustomMessage”
@EdMorales,实际上不是。当传递给属性时,Angular 2将计算
{{}
。试着玩一下。你用的是什么版本的angular?我使用的是rc.0,但不起作用。只是看到了,beta.17。TBH可能已更改,因为在rc.0中它被视为字符串。但谁知道呢。很多事情都会改变,直到它足够成熟。Plunker是beta.17版,但我也检查了本地(rc.1),以确保我没有错过任何东西。这两种方法都是一样的。实际上,第三种方法仍然作为字符串使用,并且它不计算变量。您基本上只是传递一个
{{myCustomMessage}
字符串值。第三个输入是
bind errorType=“myCustomMessage”
@EdMorales,实际上不是。当传递给属性时,Angular 2将计算
{{}
。试着玩一下。你用的是什么版本的angular?我使用的是rc.0,但不起作用。只是看到了,beta.17。TBH可能已更改,因为在rc.0中它被视为字符串。但谁知道呢。很多事情都会改变,直到它足够成熟。Plunker是beta.17版,但我也检查了本地(rc.1),以确保我没有错过任何东西。两者的效果相同。
Parser Error: Got interpolation ({{}}) where expression was expected at column 0
<msgfooter [errorType]="myCustomMessage"><msgfooter>
<msgfooter errorType="Invalid server"><msgfooter>
<msgfooter errorType="{{myCustomMessage}}">