Skip to content

Instantly share code, notes, and snippets.

@dwelch2344
Created January 14, 2014 04:16
Show Gist options
  • Save dwelch2344/8412952 to your computer and use it in GitHub Desktop.
Save dwelch2344/8412952 to your computer and use it in GitHub Desktop.
A sample of a colorPicker directive that utilizes jQuery (but plays nice with Angular)
app.directive('colorPicker', function() {
return {
scope: {
color: '=colorPicker'
},
link: function(scope, element, attrs) {
element.colorPicker({
// initialize the color to the color on the scope
pickerDefault: scope.color,
// update the scope whenever we pick a new color
onColorChange: function(id, newValue) {
scope.$apply(function() {
scope.color = newValue;
});
}
});
// update the color picker whenever the value on the scope changes
scope.$watch('color', function(value) {
element.val(value);
element.change();
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment