I\'m trying to conditionally apply a directive to an element based on its class.
Here\'s a simple case of my issue, see the results in this fiddle. For this example,
According to me don't use a conditional directive based on a class set by ng-class like this question.
Don't use this
This will have the directive applied as I expect
This will not have the directive applied but I expect it to
because it is really very complicated to handle in complex situation, so always use conditions in your custom directive.
Use this
link: function (scope, element, attrs) {
scope.$watch('condition', function(condition){
if(condition){
// something going here
}
else{
// something going here
};
});
}