In my directive I created an isolated scope binding an expression to an attribute:
scope: {
foo: '@'
}
And in the directive if I try to console log scope.foo
, I will get the following function:
function (locals) {
return parentGet(scope, locals);
}
And then executing scope.foo()
will invoke the expression in the parent's scope. The problem is, the expression I am passing in is an optional callback, but I have no safe way of telling if the attribute is defined from the parent. I will get the function no matter what expression the attribute holds, even if it wasn't specified.
As a result, testing for the existence of scope.foo
obviously doesn't help, and I can't test for scope.foo()
because that will evaluate the expression if there is one. Is there a good way to make the expression binding optional? I wish we have something similar to '=?'
when binding expressions, but there doesn't seem to be a '&?'
.