Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bind dynamic data to aria-label?

I have dynamic text to bind to aria-label on a HTML page. This is an Angular 2 app. I am using something like this:

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

But I get an error:

Can't bind to 'aria-label' since it isn't a known property of 'div'.

Is there any workaround for this?

like image 413
namrata Avatar asked Mar 07 '17 21:03

namrata


People also ask

What is ATTR aria-label in angular?

In the template, the aria-label attribute ensures that the control is accessible to screen readers.

Can aria-Labelledby have multiple ids?

Like aria-describedby , aria-labelledby can accept multiple ids to point to other elements of the page using a space separated list. This capability makes aria-labelledby especially useful in situations where sighted users use information from the surrounding context to identify a control.

Can I use aria-label on span?

Don't use aria-label or aria-labelledby on a span or div unless its given a role . When aria-label or aria-labelledby are on interactive roles (such as a link or button ) or an img role, they override the contents of the div or span .

What is Arialabelledby?

The aria-labelledby property enables authors to reference other elements on the page to define an accessible name. This is useful when using elements that don't have native support for associating elements to provide an accessible name. Some elements get their accessible name from their inner content.


1 Answers

Just use attr. before 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

Ps. As @Simon_Weaver mentioned, there are some components that implements its own aria-label @Input, like mat-select.

See his answer here Angular Material mat-label accessibility

like image 139
Bruno João Avatar answered Sep 18 '22 01:09

Bruno João