ng-class does not remove a class that was there before angular was bootstrapped

时光总嘲笑我的痴心妄想 提交于 2019-12-03 23:25:00

Since you're only using Angular for the form and need a class to be active on elements within the form prior to Angular bootstraping it looks like a directive may be the best way to go.

The following directive will remove the specified class from the element its on once the directive is linked in by Angular (which is almost the same point when ngClass will kick in):

.directive('removeClass', function(){
    return {
        restrict: 'A',
        link: function(scope,element, attrs){
            element.removeClass(attrs.removeClass);
        }
    };
});

Used like so:

<div class="oldClass" remove-class="oldClass" ng-class="{newClass: true}">stuff</div>

demo fiddle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!