简体   繁体   English

将数据绑定到 Angular 内的非本地 html 属性

[英]binding data to a nonnative html property within Angular

I like to bind some data from database to an unnatural tag element in an Angular app, this is related to "Isotope filter": I want to change this我喜欢将数据库中的一些数据绑定到 Angular 应用程序中的非自然标签元素,这与“同位素过滤器”有关:我想改变这个

 <li><a href="#" data-filter=".joomla"></li>

to

 <li *ngFor="let cat of categories;index as i"> <a href="#" class="active" [data-filter]=categoriesId[i]>{{cat.Title}}</a>

where categoriesId is an array of string in my ts file, but I face this error:其中 categoriesId 是我的 ts 文件中的字符串数组,但我遇到了这个错误:

Can't bind to 'data-filter' since it isn't a known property of 'a'.无法绑定到“数据过滤器”,因为它不是“a”的已知属性。

am I doing an impossible action?我在做一个不可能的动作吗? if yes is there any solution to do something like that?如果是的话,有什么解决方案可以做这样的事情吗?

You can use the Attribute binding syntax which is documented here :您可以使用此处记录的属性绑定语法:

 <li *ngFor="let cat of categories;index as i"> <a href="#" class="active" [attr.data-filter]=categoriesId[i]>{{cat.Title}}</a> </li>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM