How to bind dynamic data to ARIA-LABEL?

[亡魂溺海] 提交于 2019-11-30 16:27:38

问题


I have dynamic text to bind to ARIA-LABEL on an 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?


回答1:


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




回答2:


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

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


来源:https://stackoverflow.com/questions/42658800/how-to-bind-dynamic-data-to-aria-label

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!