I have a custom angular directive which for the sake of brevity we'll just call map.
It has an isolate scope set up like this.
scope: {
latitude: '=?',
longitude: '=?',
draggable: '=?'
},
I normally put something in my link function which sets scope values to be either what has been set in the attribute, or a default if nothing has been set so the devoloper can add draggable="false" if they want, otherwise we'll automatically default it to true, so in the link function I would have this.
$scope.draggable = angular.isDefined($scope.draggable) ? $scope.draggable : myDefaults.draggable;
The problem is that I want all of the following to be valid uses in html
<map draggable></map>
<map draggable="true"></map>
<map draggable="false"></map>
but the first line won't work because angular.isDefined() is false.
Should I check whether it is defined first and if it isn't then use something like attrs.draggable to see if the attribute exists before falling back on the default?
If so then there is a further complication because I need to put my code in the controller not the link function (because it needs to talk to child directives) and I don't have access to "attrs" or "element" from the controller.
Any help would be much appreciated.