1

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

Kappys
  • 673
  • 2
  • 7
  • 20
  • 1
    Chances are you're having a single-page app there? Because in that case, rewriting a URL might just fire a RouteChange event internal to angular, and the page is changed without reloading the browser window. – doldt Feb 06 '15 at 09:41
  • I need that if I refresh the page from browser bar , this page still working, but I need that this directive work when page is loaded, when the stylesheets is loaded – Kappys Feb 06 '15 at 09:51

2 Answers2

1

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

Kappys
  • 673
  • 2
  • 7
  • 20
0

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

Community
  • 1
  • 1
kasoban
  • 2,107
  • 17
  • 24
  • pff sorry for my english... I need that event work when I loaded the stylesheets, if I quit this event the directive work fine but I need wait to the stylesheets for apply my directive – Kappys Feb 06 '15 at 09:56