【发布时间】:2019-10-15 22:45:46
【问题描述】:
我正在尝试使用 angular 8 中的变量设置样式属性,但我无法让它工作。
<ng-container *ngFor="let appointmentSlot of timeslots; let i = index">
<div ngxSlickItem class="cards-slot slick-slide animation-show-slide-up"
style='{{"--animation-delay:" + i}}'>
</div>
</ng-container>
谁能解释为什么样式属性没有打印?
似乎无法绑定该属性,因为它不安全。还是可以打印吗?
我发现这行得通:
constructor(private sanitizer: DomSanitizer){}
getStyling(index: number) {
const styleAttribute = "--animation-delay: " + index;
return this.sanitizer.bypassSecurityTrustStyle(styleAttribute);
}
【问题讨论】:
-
您是否尝试过绑定到
NgStyle? angular.io/api/common/NgStyle -
我确实需要 style="--animation-delay: 1" 出现在标签中,这样我的 css 才能把它捡起来
标签: angular attributes interpolation