#In a template, can I attach an object to an element that isn't the root element of the component?

11 messages · Page 1 of 1 (latest)

boreal oracle
#

Because it's not the root element, I can't use @Input. I can't use data-*, because it stringifies everything.

#

I'm hoping to avoid creating a child component

boreal oracle
#

I ended up writing an attribute directive that adds it as a property

manic jewel
#

if cannot use data-* any where ? then i am loosing the power for the using inbuilt functionality for the element right.
I mean , i am not able to bind value to the data-* attributes.

boreal oracle
#

You can if your data is just a string

manic jewel
#

i mean dyanmic data i want to

boreal oracle
#

The string can be dynamic. You just can't use objects, arrays etc

manic jewel
#

[data-id]="test" in template and test="test" in ts did these.

#

Error: apps/recipe-app/src/app/ingredient/ingredient.component.html:1:6 - error NG8002: Can't bind to 'data-id' since it isn't a known property of 'div'.

boreal oracle
#

Try [attr.data-id]

manic jewel
#

works man, Thank you a lot