I'm trying to use custom attributes on inputs and divs. When I put static data like this:
我正在尝试在输入和div上使用自定义属性。当我把这样的静态数据:
<input type="hidden" class="test" value="0" custom-data='12345' />
The code works fine. But when I use data from a loop for example:
代码工作正常。但是当我使用循环数据时,例如:
<input type="hidden" class="test" value="0" custom-data='{{ data.id }}' />
I get this error:
我收到此错误:
Unhandled Promise rejection: Template parse errors:
Can't bind to 'custom-data' since it isn't a known property of 'input'.
<input type="hidden" class="test" value="0" [ERROR ->]custom-data='{{ data.id }}' />
2 个解决方案
#1
4
You should always use the bracket notation when setting inputs to an expression:
在为表达式设置输入时,应始终使用括号表示法:
<input type="hidden" class="test" value="0" [custom-data]="data.id" />
#2
0
remove the curly brackets and add the value
删除花括号并添加值
<input type="hidden" class="test" value="0" custom-data='data.id ' />
since custom-data
is a directive no need to use the curly brackets when you are binding values to directive attributes
由于custom-data是一个指令,因此在将值绑定到指令属性时不需要使用花括号
#1
4
You should always use the bracket notation when setting inputs to an expression:
在为表达式设置输入时,应始终使用括号表示法:
<input type="hidden" class="test" value="0" [custom-data]="data.id" />
#2
0
remove the curly brackets and add the value
删除花括号并添加值
<input type="hidden" class="test" value="0" custom-data='data.id ' />
since custom-data
is a directive no need to use the curly brackets when you are binding values to directive attributes
由于custom-data是一个指令,因此在将值绑定到指令属性时不需要使用花括号