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

后端 未结 1 607
既然无缘
既然无缘 2021-02-19 03:59

Still under 72 hours coming up to speed with angular. Having used knockout for a while, I have to say it\'s interesting. My question right now has to do with ng-class.

相关标签:
1条回答
  • 2021-02-19 04:38

    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

    0 讨论(0)
提交回复
热议问题