首页 > 解决方案 > 将元素的 ngClass 条件绑定到它的父 div 属性

问题描述

我的 html 中有这样的块:

<div #eventOrderHead class="table__cell left clickable nowrap" [appSort]="events" data-order="desc" style="width: 1%;" data-name="order">
                            <span [ngClass]=" <bind to data-order> ? 'whis-sorting sorting-top' : 'whis-sorting sorting-bottom'">
                                №
                                <svg width="8" height="10" viewBox="0 0 8 10" fill="none" xmlns="http://www.w3.org/2000/svg">
                                    <path class="bottom" fill-rule="evenodd" clip-rule="evenodd" d="M0 6L4 10L8 6" fill="#9F9F9F" />
                                    <path class="top" fill-rule="evenodd" clip-rule="evenodd" d="M8 4L4 -4.29138e-07L0 4" fill="#9F9F9F" />
                                </svg>
                            </span>
                        </div>

如何在我的 ngClass 条件中绑定到 div 的数据顺序属性?

我试着简单地写 "eventOrderHead.data-order == 'asc'" 但这会导致错误"Can't bind to 'data-order' because it is not a known property of 'div'"

标签: angularbindingattributesng-class

解决方案


推荐阅读