Can one create a isolate scope with optional ampersand (parent context) data binding?
scope: {
myMethod: '&?'
}
If the directive is implemented without assigning myMethod, there is no error. However, I see that when the optional property is not assigned, angular assigns it a noop function anyways. Therefore, there appears to be no way to know, within the directive, if the implementer assigned the optional property a method or not.
link: function (scope, element, attrs) {
scope.myMethod(); //this calls a noop function instead of being undefined, as i exected
}
Any insights? I'd like to know if the implementor has assigned the optional property.
Check the attrs
object to see if it was populated:
link: function (scope, element, attrs) {
if (attrs.myMethod) {
scope.myMethod();
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments