Skip to content

Commit 7b4e013

Browse files
committed
Fixing up setting ng-model to null
1 parent a466788 commit 7b4e013

File tree

7 files changed

+14
-8
lines changed

7 files changed

+14
-8
lines changed

angularjs-color-picker.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angularjs-color-picker.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Copyright 2015 ruhley
66
*
7-
* 2015-09-28 08:53:52
7+
* 2015-10-15 10:30:38
88
*
99
*/
1010
if (typeof module !== "undefined" && typeof exports !== "undefined" && module.exports === exports){
@@ -152,7 +152,7 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
152152
};
153153

154154
$scope.$watch('ngModel', function (newValue, oldValue) {
155-
if (newValue !== undefined && newValue !== oldValue && newValue.length > 4) {
155+
if (typeof newValue === 'string' && newValue !== oldValue && newValue.length > 4) {
156156
$scope.log('Color Picker: MODEL - CHANGED', newValue);
157157
var color = tinycolor(newValue);
158158

@@ -177,6 +177,8 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
177177
if (oldValue !== undefined) {
178178
control[0].$setDirty();
179179
}
180+
} else {
181+
$scope.swatchColor = '';
180182
}
181183
});
182184

angularjs-color-picker.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angularjs-color-picker.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angularjs-color-picker.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/02-testing-lib.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ <h1>AngularJS Color Picker</h1>
7474
color-picker-case="case"
7575
color-picker-swatch-only="swatchOnly">
7676
</color-picker>
77+
78+
<button class="btn btn-primary" ng-click="color = null;">Clear</button>
7779
</div>
7880

7981
<div class="row">

lib/scripts/directive.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
};
134134

135135
$scope.$watch('ngModel', function (newValue, oldValue) {
136-
if (newValue !== undefined && newValue !== oldValue && newValue.length > 4) {
136+
if (typeof newValue === 'string' && newValue !== oldValue && newValue.length > 4) {
137137
$scope.log('Color Picker: MODEL - CHANGED', newValue);
138138
var color = tinycolor(newValue);
139139

@@ -158,6 +158,8 @@
158158
if (oldValue !== undefined) {
159159
control[0].$setDirty();
160160
}
161+
} else {
162+
$scope.swatchColor = '';
161163
}
162164
});
163165

0 commit comments

Comments
 (0)