Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rebelholic/d7fd0646e43b3bca306124838c73e070 to your computer and use it in GitHub Desktop.
Save rebelholic/d7fd0646e43b3bca306124838c73e070 to your computer and use it in GitHub Desktop.
Random Background Color Directive for Angularjs
// just add random-backgroundcolor to the element you want to give a random background color
app.directive("randomBackgroundcolor", function () {
return {
restrict: 'EA',
replace: false,
link: function (scope, element, attr) {
//generate random color
var color = '#' + (Math.random() * 0xFFFFFF << 0).toString(16);
//Add random background class to selected element
element.css('background-color', color);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment