Skip to content

Commit 32d8857

Browse files
committed
Bug #102 non assign error if options was set in html
1 parent 24e0b48 commit 32d8857

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

examples/01-simple.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ <h1>AngularJS Color Picker</h1>
147147
<div class="row">
148148
<h2>No Options</h2>
149149
<label class="control-label">Color</label>
150-
<color-picker ng-model="color2"></color-picker>
150+
<color-picker class='col-sm-1' ng-model="entity.color" options="{'format':'hex','swatchOnly':true}" /></color-picker>
151151
</div>
152152

153153
<div class="row">

src/scripts/controller.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ export default class AngularColorPickerController {
365365
}
366366

367367
initConfig () {
368-
this.options = this.merge(this.options, this.ColorPickerOptions);
368+
this.mergeOptions(this.options, this.ColorPickerOptions);
369369

370370
this.visible = this.options.inline;
371371

@@ -374,29 +374,18 @@ export default class AngularColorPickerController {
374374
}
375375
}
376376

377-
merge(options, defaultOptions) {
378-
var newObject = {};
377+
mergeOptions(options, defaultOptions) {
379378
var attr;
380379

381380
for (attr in defaultOptions) {
382381
if (defaultOptions.hasOwnProperty(attr)) {
383-
newObject[attr] = defaultOptions[attr];
384-
}
385-
}
386-
387-
if (typeof options === 'object') {
388-
for (attr in options) {
389-
if (options.hasOwnProperty(attr)) {
390-
if (typeof options[attr] === 'object') {
391-
newObject[attr] = this.merge(options[attr], newObject[attr]);
392-
} else {
393-
newObject[attr] = options[attr];
394-
}
382+
if (!options || !options.hasOwnProperty(attr)) {
383+
options[attr] = defaultOptions[attr];
384+
} else if (typeof defaultOptions[attr] === 'object') {
385+
this.mergeOptions(options[attr], defaultOptions[attr]);
395386
}
396387
}
397388
}
398-
399-
return newObject;
400389
}
401390

402391
focus () {

0 commit comments

Comments
 (0)