directives with isolated scope and a optional function '&?' should be returned as undefined if the function is missing #6404
Description
Overview of the issue
It is not a bug, probably just a design issue about directives with isolated scope and optional functions passed via '&?'.
If you don't pass any function to the directive, you get a function that returns undefined instead of undefined.
Errors
No errors are thrown.
Motivation for or Use Case
If you declare a scope property as optional, probably the expected behaviour is getting undefined if you try to access this property.
This is exactly what happens when you have a '@?' binding and you don't fill in the optional attribute: you get undefined trying to access $scope.property.
The way to understand if there is a function parameter is inspecting the attrs.
So this seems a special case not motivated for '&?'.
Angular Version(s)
All versions, no regression.
Browsers and Operating System
All browsers and operting systems.
Suggestion
In order to get a common behaviour for optional parameters you could just add the following control to
Line 1463 in 4a6a3ba
if (optional && !attrs[attrName]) {
return;
}
If you find that this proposal is ok I can make a pull request from: https://github.com/davidemoro/angular.js/blob/master/src/ng/compile.js
I've just run the tests and all seems fine.