ruhley / angular-color-picker

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

Colorpicker doesn't show up correctly when using a variable as a placeholder #122

Closed kinging123 closed 8 years ago

kinging123 commented 8 years ago

Here's a Plunkr demo: https://plnkr.co/edit/Ho9NBEogYkqrU0w6UpnV?p=preview

The placeholder shows just fine but everything else is messed up.

This code works:

    <color-picker ng-model="primary_color" options="{placeholder: '#123456'}" ></color-picker>

This doesn't:

    <color-picker ng-model="primary_color1" options="{placeholder: myColor}" ></color-picker>

(When $scope.myColor is defined)

nati-mask commented 8 years ago

Your Plunkr shows me good results, the placeholders are as intended...

kinging123 commented 8 years ago

Forgive me if I haven't described the issue correctly.

The placeholders are working just fine, but try to click on the colorpicker:

The second one works fine: image

The first one though shows only red colorpicker and no bootstrap addon: image

ruhley commented 8 years ago

In your scenario on this line (https://github.com/ruhley/angular-color-picker/blob/master/src/scripts/controller.js#L402) it tries to merge the passed in options object with the default options object. Logging out the options object after the merge function results in the expected output. However outputting the options object in the html {{AngularColorPickerController.options}} only shows the provided options object, not the merged one. This only happens when using and inline options object -

<color-picker ng-model="color" options="{placeholder: myColor}" ></color-picker>

This does not happen if the options object is a defined variable and still using a variable in the placeholder.

$scope.options = {
    placeholder: myColor
};
<color-picker ng-model="color" options="options" ></color-picker>

It also works as expected if after the merge I assign the options object to another variable this.optionsClone = this.options; and then use that. I feel like this is some sort of weird AngularJS bug that two way binding doesn't work on inline objects with a variable.

If you absolutely have to pass in the options object inline then I put in the optionsClone hack for you. However I would rather fix the root cause of the problem.

ruhley commented 8 years ago

I am closing this issue as there has not been an update in a while and I believe it is an AngularJS bug. Please reopen this issue if you feel it has not been resolved.