Created
January 14, 2014 04:16
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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