ruhley / angular-color-picker

Vanilla AngularJS Color Picker Directive with no requirement on jQuery
http://ruhley.github.io/angular-color-picker/
MIT License
166 stars 79 forks source link

TypeError: Cannot read property 'length' of null #44

Closed rbecheras closed 8 years ago

rbecheras commented 8 years ago

TypeError: Cannot read property 'length' of null at Object.fn (angularjs-color-picker.js:155) at Scope.$digest (angular.js:14394) at Scope.$apply (angular.js:14657) at done (angular.js:9734) at completeRequest (angular.js:9924) at XMLHttpRequest.requestLoaded (angular.js:9865)(anonymous function) @ angular.js:11707(anonymous function) @ angular.js:8628Scope.$digest @ angular.js:14412Scope.$apply @ angular.js:14657done @ angular.js:9734completeRequest @ angular.js:9924requestLoaded @ angular.js:9865

In the code:

$scope.$watch('ngModel', function (newValue, oldValue) {
  if (newValue !== undefined && newValue !== oldValue && newValue.length > 4) {
    ...
  }
}

Needs to be replaced by the following snippet to not crash for null value of the model:

$scope.$watch('ngModel', function (newValue, oldValue) {
  if (newValue !== undefined && newValue !== null && newValue !== oldValue && newValue.length > 4) {
    ...
  }
}

I will make a pull request