Created
August 26, 2015 06:25
-
-
Save gayanvirajith/e6609f7abc6452f82558 to your computer and use it in GitHub Desktop.
Angular after render directive trick
This file contains 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
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