I'm having a problem which seems completely crazy! I use a directive that takes some attributes bound to its scope, that take a value from a parent scope variable. All very normal.. ...except when I do console.log(scope), the attributes are displayed normally as scope object's properties with the expected value, but when I do console.log(scope.myAttr) then I get undefined!!
Has anyone encountered something like this before??
// In parent directive:
scope.datepickerOptions.enableTime = false;
// In directive:
angular.module('myModule')
.directive('datepicker', function() {
return {
require: 'ngModel',
restrict : 'A',
scope: {
format: '@',
enableTime: '=',
minDate: '@',
maxDate: '@',
mode: '@'
},
link : function(scope, element, attrs, ngModel) {
console.log("scope")
console.log(scope)
// displays all properties with expected values
//=> scope.enableTime: false
console.log("enableTime")
console.log(scope.enableTime)
// undefined (!!!)
...
// In parent template:
...
<input
type="text"
id="events_date"
name="events_date"
ng-model="events.selectedDate"
placeholder="Select Date Range"
ng-change="setQueryDate()"
format="d M Y"
mode="range"
enable-time="datepickerOptions.enableTime"
max-date="today"
datepicker>
...
I also tried: enable-time="{{datepickerOptions.enableTime}}" with enableTime: '@'
and I get the same craziness when I do console.log(attrs) and console.log(attrs.enableTime)
Same thing when I put a controller with $scope argument: console.log($scope) displays everything normally, but console.log($scope.enableTime) gives undefined