Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Validating if markup options are really set in $scope #3625

Closed
wants to merge 1 commit into from

Conversation

kreigiron
Copy link
Contributor

Validates if options are really set in $scope when datepicker-options="options" is given in markup, but no $scope.options exists.

otherwise it will throw an error like:

TypeError: Cannot read property 'initDate' of undefined
at link (http://localhost:3000/bower_components/angular-bootstrap/ui-bootstrap-tpls.js:1523:19)
at http://localhost:3000/bower_components/angular/angular.js:8252:44
at invokeLinkFn (http://localhost:3000/bower_components/angular/angular.js:8258:9)

....

Validates if options is really set in $scope, otherwise it will throw an error like:

TypeError: Cannot read property 'initDate' of undefined
    at link (http://localhost:3000/bower_components/angular-bootstrap/ui-bootstrap-tpls.js:1523:19)
    at http://localhost:3000/bower_components/angular/angular.js:8252:44
    at invokeLinkFn (http://localhost:3000/bower_components/angular/angular.js:8258:9)
@311chaos
Copy link

311chaos commented May 5, 2015

I am getting this error "Cannot read property 'initDate' of undefined as well. This only started occurring after updating from 0.12.1 to 0.13.0. What I am trying to understand is if I need to change my values that are getting passed into the directive.

@kreigiron
Copy link
Contributor Author

@311chaos Indeed, this happened to me after updating from 0.12.x to 0.13.x, and when I have the "datepicker-options="options"" attribute defined, but no $scope.options is defined. It seems that the old version didn't really care about $scope.options existence.

@311chaos
Copy link

311chaos commented May 5, 2015

Well, what seems to have changed is the $scope. All of my values are on the $parent scope. So I had:

data-datepicker-options="SRCtrl.datepicker.dateOptions"

but it needs to be changed to:

data-datepicker-options="$parent.SRCtrl.datepicker.dateOptions"

I can work around this, but it isn't obvious and I don't love referencing the $parent. Perhaps I am doing something else wrong?

@karianna karianna added this to the 0.13.1 (Performance) milestone May 6, 2015
@wesleycho
Copy link
Contributor

I think a better fix might be options = scope.$parent.$eval(attrs.datepickerOptions) || {}.

@wesleycho wesleycho modified the milestones: 0.13.1 (npm), 0.13.2 (Performance) Jul 23, 2015
@wesleycho wesleycho closed this in 577b2a2 Jul 31, 2015
@wesleycho
Copy link
Contributor

I decided to merge as is - this is probably a better check to avoid mutating the value.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants