通过ng-class根据属性值添加和删除类

Adding and removing class through ng-class based on attribute value

本文关键字:添加 删除 属性 ng-class 通过      更新时间:2023-09-26

考虑下面的标记。这是手风琴的外壳。我必须应用不同的css(背景色)的一个是开放的。为此,我希望使用ng-class指令。现在打开的标题总是将aria-expanded属性设置为true。对别人都是假的。

<v-pane-header class="header ng-scope ng-isolate-scope" role="tab" tabindex="0" aria-selected="true" aria-expanded="true">

我怎样才能做到这一点。我知道如何对任意模型变量进行求解。注意:aria-expanded属性是由accordion插件自动添加的。

我采取了一种非常不同的方法来解决这个问题。我没有通过ng-class或代码中的任何其他函数或方法来实现这一点,而是在accordion插件本身上工作。手风琴动态添加aria-expanded属性。所以我在插件代码中进行了更改,并从插件添加aria-expanded属性的地方应用了style属性。现在工作得很好。

function expand() {
    accordionCtrl.disable();
    paneContent.attr('aria-hidden', 'false');
    paneHeader.attr({
        'aria-selected': 'true',
        'aria-expanded': 'true',
        'style': 'background-color:#FFF0C9 !important'  // Added style here. Can add a class too though.
    });
    emitEvent('onExpand');
    // Rest of the code......

这不是对我通过ng-class来实现它的问题的答案,但仍然给任何试图实现类似事情的人提供了一个可能的方法。