Reputation: 703
I'm working with AngularJS Framework and I have a problem... I have a directive that only work when the windows is loaded.
screensCreators.directive('createscreen', function () {
return {
restrict: "A",
transclude: true,
scope: false,
link: function (scope, element, attrs) {
$(window).load(function () {
console.log(scope);
});
};
};
});
When I prove refresh page pressing "F5" or pressing button in bar of browser, my page have a directive and these work fine... but if I refresh or load page from bar, writting url in bar and load... my directive not working because not enter in load event....
why?
thanks
Upvotes: 1
Views: 490
Reputation: 703
I solve my problem...
It is very easy and not very elegant ...
I needed this Directive load after page loaded ... and the events "load","afterprinting",... not worked fine
my solution is add a TimeOut with time " 1" , with this, When the page loaded , always load the script after
setTimeout(function(){....},1);
I know is not the best solution but it work fine for me. Thanks
Upvotes: 1
Reputation: 2167
Depending on what you want to do, waiting for the load event is not the way to go.
Generally load will only be executed on the first page load, after that you aren't really reloading the page but instead execute route changes if you navigate within a single page application.
Please refer to this related question and the documentation for $route
Upvotes: 0