First of all active
is in an isolate scope, so ng-class
has no access to it.
Secondly, and more importantly, ng-class
is added after the directives of the element have been collected by angular. It's too late.
There's no reason to use ng-class
if you have your own directive.
slideMenu.directive('asmSlideLeft', ['$rootScope', 'asmService',
function($rootScope, asmService) {
return {
restrict: 'AEC'
...
link: function(scope, element) {
element.addClass('asm asm-horizontal asm-left');
$rootScope.$on('asmEvent', function() {
if (asmService.asmStates.slideLeft.active) {
element.addClass('asm-left-open');
}
else {
element.removeClass('asm-left-open');
}
...