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

Set default color to color-picker #56

Closed ReactionCode closed 8 years ago

ReactionCode commented 8 years ago

Hi @ruhley. Thanks for your share your awesome work! ;)

I'm working with your module to create an html editor. and I'm trying to pass a default color to the color picker.

I tried

var color = "#FF0000"; // I get the color element by Jquery
$scope.ngModel = color // does nothing.
$scope.myColor = color; // only sets the color when I click on edit the color, but when show the modal is set as #FFFFFF

I have an example on https://plnkr.co/edit/HycbM4zEOENvreXfsFPj?p=preview

You have to click in one of the html modules.

Can you give me some orientation?

Thanks for your help. Javier

ruhley commented 8 years ago

To get your example working I needed to add $scope.$apply() at the end of the function. See it working at https://plnkr.co/edit/h6oZwXKfxkm1UZ5qY2f2?p=preview. This is because you are attching the click event using normal javascript. If you used ng-click="" instead then you wouldn't have this problem. This is considered best practice.