Skip to content

Instantly share code, notes, and snippets.

@gayanvirajith
Created August 26, 2015 06:25
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 gayanvirajith/e6609f7abc6452f82558 to your computer and use it in GitHub Desktop.
Save gayanvirajith/e6609f7abc6452f82558 to your computer and use it in GitHub Desktop.
Angular after render directive trick
define(['angular'], function (angular) {
'use strict';
return angular.module('app.common.after-render', [])
.directive('afterRender', [ '$timeout', function($timeout) {
var def = {
restrict : 'A',
terminal : true,
transclude : false,
link : function(scope, element, attrs) {
if (attrs) { scope.$eval(attrs.afterRender) }
scope.$emit('onAfterRender')
}
};
return def;
}]);
});
then you can do:
<div after-render></div>
or with any useful expression like:
<div after-render="$emit='onAfterThisThingRendered'"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment