Created
June 6, 2014 19:33
-
-
Save rosslavery/097dd81cac42d4d714d9 to your computer and use it in GitHub Desktop.
Iconic AngularJS Injection
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('iconic', function() { | |
return { | |
restrict: 'A', | |
link: function(scope, element, attrs) { | |
scope.$watch(function() { | |
// Watch for the number of iconic DOM elements | |
return element.find('img.iconic').length; | |
}, function(newLength, oldLength) { | |
// If a new element was added | |
if (newLength > oldLength) { | |
IconicJS().inject('img.iconic'); | |
} | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment