I hav a directive that looks roughly like this, with an ng-class
in the template:
module.directive('myDirective', [function() {
return {
restrict: 'E',
template: `<div ng-class="{'foo-expanded': expanded, 'foo': !expanded}"><div>`
//...
}
}]);
My problem is, my classes from the ng-class
are applied to the div
, which ends up being nested inside of the directive element after the directive is compiled: <my-directive><div>...</div></my-directive>
.
Is there any way to apply the classes to the root <my-directive>
element instead? I know I can dynamically add the class using javascript in the link function or controller instead of the ng-class
, but I am looking for a way to avoid this.