gonewandering / angles

An angular.js wrapper for Chart.js
MIT License
632 stars 87 forks source link

Exception when used with late data binding #33

Closed NateRedding closed 10 years ago

NateRedding commented 10 years ago

I am using Angles with a forked version of chartjs (https://github.com/Regaddi/Chart.js). I get the following error when I use it in a late databinding situation:

TypeError: Cannot read property 'labels' of undefined at calculateDrawingSizes (http://localhost:8081/vendor/nnnick-chartjs/Chart.js:1484:24) at new Bar (http://localhost:8081/vendor/nnnick-chartjs/Chart.js:1333:3) at Bar (http://localhost:8081/vendor/nnnick-chartjs/Chart.js:556:10) at Object. (http://localhost:8081/vendor/angles/angles.js:46:28) at Object.ng.config.$provide.decorator.$delegate.proto.$watch.applyFunction as fn at Scope.$get.Scope.$digest (http://localhost:8081/vendor/angular/angular.js:12357:29) at Scope.ng.config.$provide.decorator.$delegate.proto.$digest (:844:31) at Scope.$get.Scope.$apply (http://localhost:8081/vendor/angular/angular.js:12622:24) at Scope.ng.config.$provide.decorator.$delegate.proto.$apply (:855:30) at done (http://localhost:8081/vendor/angular/angular.js:8234:45)

I think the problem is that the $watch function gets called once before the promise has been resolved. It looks like there might have once been protection against this as there is a comment in the Angles code saying to "if data not defined, exit". However there is no code to exit.

            $scope.$watch("data", function (newVal, oldVal) { 
                // if data not defined, exit
                if ($scope.chart) { type = $scope.chart; }
                ...
            }

The error occurs when 'newVal' is undefined.

gonewandering commented 10 years ago

Hey Nate, Thanks. I've set aside some time tomorrow to overhaul this little wrapper. If you want to do a pull request re-adding that in the meantime, feel free! -- Lindsay