Is it possible to determine if a specific attribute exists in a directive, ideally using isolate scope or the attributes object as a last resort?
If we have a directive like this
<project status></project>
, I would like to display a status icon conditionally, but only when the status attribute is present.
return {
restrict: 'AE',
scope: {
status: '@'
},
link: function(scope, element, attrs) {
scope.status === 'undefined'
}
}
It would be best if the attribute was directly bound to the scope for use in the template. However, the value of the bound variable is undefined. This applies to both &
read-only and =
two-way bindings as well.
I understand that adding
<project status='true'></project>
would solve the issue easily, but for commonly used directives, I prefer not to do so (XHTML validation is not a concern).