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 direct
Since the attrs
value is type of javascript object
. To check attribute existence we can also using hasOwnProperty()
method instead in
keyword.
So, it could be :
link: function(scope, element, attrs) {
var is_key_exist = attrs.hasOwnProperty('status');//Will return true if exist
}
You can read further the difference between in
keyword and hasOwnProperty()
method at this link