Skip to content

Instantly share code, notes, and snippets.

Created March 13, 2018 15:05
Show Gist options
  • Save anonymous/879f6a6929b6ffee0cd882c9692ddbc8 to your computer and use it in GitHub Desktop.
Save anonymous/879f6a6929b6ffee0cd882c9692ddbc8 to your computer and use it in GitHub Desktop.
Angular: after-render (source: https://jsfiddle.net/loduarte/h53okjtu/220/)
<div ng-app="myApp" ng-controller="MyCtrl">
<div after-render="missionCompled">element</div>
</div>
var myApp = angular.module('myApp',[]);
myApp.directive('afterRender', ['$timeout', function ($timeout) {
var def = {
restrict: 'A',
terminal: true,
transclude: false,
link: function (scope, element, attrs) {
$timeout(scope.$eval(attrs.afterRender), 0); //Calling a scoped method
}
};
return def;
}]);
myApp.controller('MyCtrl', function ($scope) {
$scope.missionCompled = function()
{
console.log('Done');
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment