Skip to content

Instantly share code, notes, and snippets.

@andyshora
Created July 20, 2013 15:01
Show Gist options
  • Save andyshora/6045373 to your computer and use it in GitHub Desktop.
Save andyshora/6045373 to your computer and use it in GitHub Desktop.
AngularJS directive to add a custom background image to an element when the app has initialized. For example: <div background-image="{{imagePath}}"></div>
'use strict';
app.directive('backgroundImage', function(){
return function(scope, element, attrs){
restrict: 'A',
attrs.$observe('backgroundImage', function(value) {
element.css({
'background-image': 'url(' + value +')'
});
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment