Is is possible to check whether a given attribute is present in a directive, ideally using isolate scope or in a worst case scenario the attributes object.
With a directive that looked something like this <project status></project>, I want to conditionally render a status icon, but only if the status attribute is present.
return {
restrict: 'AE',
scope: {
status: '@'
},
link: function(scope, element, attrs) {
scope.status === 'undefined'
}
}
Ideally, it would be bound straight to the scope, so that it could be used in the template. However, the bound variable's value is undefined. The same goes for & read-only and = two-way bindings.
I know that it's trivially solved by adding a <project status='true'></project>, but for directives that I will use frequently, I'd rather not have to. (XHTML validity, is not an issue).
"status" in attrsand see what that evaluation is?scope.status === 'undefined'<== doesn't do anything all by itself. What are you expecting?