babbaggeii
babbaggeii

Reputation: 7737

How to delay directive compile until after window load event

I want to delay certain directives to only compile after the window load event. They are below the fold and are slowing down the overall Angular bootstrapping process.

So to this end, I want to create an attribute directive that I can add to directives that will delay their compile function - is this possible?

Upvotes: 0

Views: 735

Answers (2)

Sangram Badi
Sangram Badi

Reputation: 4264

Using $timeout you can put delay functionality.

return function(scope, element, attrs) {
    $timeout(function(){

    });        
}

and don't forget to inject $timeout

.directive('directiveName', function($timeout)

Upvotes: 1

Artur Joshi
Artur Joshi

Reputation: 75

Try to put your logic after onload event. In order to do this, you should use $(window).load() or $(document).ready().

Hope it helps!

Upvotes: 0

Related Questions