Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it possible to bind an angular property value into the value of an html attribute?

Is it possible to bind an Angular property value to a data attribute on a template element?

Here’s an example.

<h1 data-name="{{name}}">Hello from {{ name }}!</h1>

When we run that stackblitz, it produces this error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Error in src/main.ts (11:9)
Can't bind to 'name' since it isn't a known property of 'h1'.

Thoughts?

>Solution :

Yes,

<h1 [attr.data-name]="name">Hello from {{ name }}!</h1>

Based on How can I write data attributes using Angular?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading