How to use addClass method in angularjs

Problem

I have an angularjs directive restricted to class. How can I add this by using addClass method in angularjs

directive

app.directive('number', function() {
return {
    restrict: 'C',
    link: function () {         

    }
};

});

code

 <div id="test"></div>

I know it is possible by using jQuery like the following.

$( "#test" ).addClass( "number" );

Please help me in doing it by using angularjs

Problem courtesy of: babtech

Solution

You don't need to use .addClass() angular provide ng-class directive to add class conditionally.

ng-class="{number:[condition]}"

it will add class number whenever your condition return true

yes but your directive will not be used by this I misunderstood your question previously.

Solution courtesy of: Shreyance Jain

Discussion

You should add ng-class="yourClass" to element on view and add in your controller

$scope.yourClass = "your-new-class", not in directive

Discussion courtesy of: Cybercarnage シ

try this

 link: function (lEmel) {         
      lElem.addClass("Foo");
    }

Discussion courtesy of: user3597009

This recipe can be found in it's original form on Stack Over Flow.