Why is $timeout running before directive render. Here is my directive
angular.module('directiveTestModule').directive('popupMessage', ['$filter', 'crudService', 'serviceConfiguration', '$rootScope', '$timeout','$parse',
function ($filter, crudService, serviceConfiguration, $rootScope, $timeout, $parse) {
return {
restrict: 'E',
replace: true,
scope: { instance:'=instance', options: '=options' },
replace: true,
templateUrl: 'Scripts/app/shared/popupMessage/popupMessageView.html',
controller: function ($scope, $element) {
},
link: function ($scope, $element, attr) {
//$scope.instance = $parse(attr['popupMessage'])($scope) || {};
$scope.instance = {};
$scope.instance.showMessage = function () {
alert($scope.options.name)
}
}
}
}]);
And here is the code on my controller
$timeout(function () {
$scope.instancePopUp.showMessage()
}, 0)
And this is the html code
<popup-message instance="instancePopUp" options="optionsPopup"></popup-message>
Sometimes, the timeout function runs before directive's link function. As long as I know timeout should be run after all directives initializations, am I wrong? Is there a way to make sure directive runs before $timeout on controller?