How to associate dynamic data with ARIA-LABEL?

I have dynamic text to bind to ARIA-LABEL on an html page. This is an angular 2 app. I'm using something like this: aria-label = "Product Details for {{productDetails? .ProductName}}"

But I get an error - Unable to bind to 'aria-label', as this is not a known property of 'div'.

Is there any workaround for this?

+16
html angular wai-aria uiaccessibility
Mar 07 '17 at 21:37
source share
2 answers

Just use attr. to aria label:

attr.aria-label="Product details for {{productDetails?.ProductName}}"

or

[attr.aria-label]="'Product details for ' + productDetails?.ProductName"

Examples here: https://stackblitz.com/edit/angular-aria-label?embed=1&file=src/app/app.component.html&hideExplorer=1

+31
Mar 07 '17 at 21:45
source share

You must use square brackets ( [ ] ) around the target property:

 [attr.aria-label]="'Product details for' + productDetails?.ProductName" 
0
Jul 02 '19 at 18:57
source share



All Articles