简体   繁体   English

角度ng级重新评估

[英]Angular ng-class re-evaulate

Im using ng-class to apply the class active when collapseSidebar is set to true revealing my sidebar. 我将ng-class设置为有效时,将collapseSidebar设置为true来显示我的侧边栏。

<div class="row full-height row-offcanvas row-offcanvas-left" ng-class="{active: collapseSidebar}">
    <div id="sidebar" class="col-sm-4 col-md-3 col-lg-3 col-xl-2 sidebar-offcanvas">
    </div>

js js

$scope.collapseSidebar = false;

    $scope.select = function(thing)
    {
        $scope.selectedThing = (thing !== $scope.selectedThing) ? thing : null;
        $scope.collapseSidebar = true;
    };

However the sidebar can be hidden in other ways (click a menu icon in the top left) removing the class active. 但是,可以通过其他方式隐藏边栏(单击左上角的菜单图标),从而删除活动的类。 When I call select(thing) I was hoping that ng-class would be re-evaluated and the class 'active' would be re-applied, however this does not happen, I have tried setting it to false and then straight back to true which also didn't work. 当我调用select(thing)时,我希望可以重新评估ng-class并重新应用“ active”类,但是这种情况不会发生,我尝试将其设置为false,然后直接返回true这也没有用。

How can I get ng-class to re-evaluate collapseSidebar and apply 'active' even if the value is the same as be 我如何获得ng-class重新评估collapseSidebar并应用“ active”,即使其值与

Have you tried: 你有没有尝试过:

ng-class="{'active': collapseSidebar}"

(The active class name is wrapped by the "'" characters) (活动的类名称由“'”字符包装)

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

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