I have a directive that receives a string, which I would like the directive to then modify and add as an attribute's property.
HTML
<div directive ng-class="" otherAttribute="hello"></div>
JS
.directive('directive', function () {
return {
link: function (scope, elem, attrs) {
var classList = "{active: attrs.otherAttribute == 'hello'}";
attrs.ngClass = classList;
console.log(attrs);
}
}
})
This does seem to add the properties to the class property of the attrs object:
console.log(attrs);
$$observers: Object
$attr: Object
ngClass: "{active: attrs.otherAttribute == 'hello'}"
otherAttribute: "hello"
__proto__: Object
But the DOM is not updated. I've tried $compile, but that does not update the class attribute on the DOM either.
What am I missing? Many thanks!