Created
July 20, 2013 15:01
-
-
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>
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
'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