2

My component has a variable which is called componentId which is defined as an input of the component:

@Input() public componentId: string;

I want this variable to be interpreted when building the HTML, in order to assign it to the attributename. Something like this:

<customTag name="{{componentId}}"/>

The issue is that customTag has no property name, so when I try to do that I get the exception:

Can't bind to 'name' since it isn't a known property of 'customTag'.

However, if I was doing this:

<customTag name="somename"/>

... in the rendered HTML I can correctly see the attribute name filled with "somename".

What I need is just to use the value of this variable (componentId) as a name of customTag, without need of actually trying to access the property name of the component customTag (on which's code I've no control since it comes from a library).

How can I just read the value of componentId to assign it dynamically to the static attribute name?

1 Answer 1

3

You can use attribute binding:

<customTag [attr.name]="componentId"></customTag>
Sign up to request clarification or add additional context in comments.

1 Comment

It worked! I'll accept your answer in 8 minutes (doesn't let me yet), thanks a lot!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.