0

I'm trying to use custom attributes on inputs and divs. When I put static data like this:

<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 Answers 2

3

You should always use the bracket notation when setting inputs to an expression:

<input type="hidden" class="test" value="0" [custom-data]="data.id" />

Sign up to request clarification or add additional context in comments.

1 Comment

how to get this custom data in .ts file and alert it (click)="test()"
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.