Ben Aston Ben Aston - 4 months ago 7
AngularJS Question

Is there a way to determine whether a directive scope "&" item has been set to something?

In the following note that

bar
does not have a value.

Instance:

<my-directive
foo="foo"
bar="" /></my-directive>


Directive:

return function() {
return {
restrict: 'E',
scope: {
foo: '&',
bar: '&',
},
template: template,
controllerAs: 'ctrl',
controller: controller,
};
};


How can I tell in the controller that
scope.bar
has not been set to anything?

I am using Angular 1.4.

Answer

Attribute value itself can be checked with

$attrs.bar == true;

As it was mentioned, & bindings result in wrapper function that is always truthy.