Anurag Mishra
Anurag Mishra

Reputation: 103

Call a function after complete page load in Angularjs

I am new to Angularjs and I am using following code to execute a function after page load. I have written this script in HTML.

<script type="text/javascript">
        $(document).ready(function(){
                showProvision(device.data.provision.endpoint_brand,device.data.provision.endpoint_model);
        });
</script>

I have used below code as well but unfortunately getting nothing whatever I want.

<script type="text/javascript">
        setTimeout(function() {
                showProvision(device.data.provision.endpoint_brand,device.data.provision.endpoint_model);
            }, 5000);

</script>

The parameters of the function will come from controller after the page load. After getting the parameters, I want to execute this function. If there is any other option or choice to do it then tell me.

Upvotes: 2

Views: 6628

Answers (1)

Arthur Kovacs
Arthur Kovacs

Reputation: 1740

Just to have this answer here for posterity, whenever you want Angular to take advantage of something external, you have to call that function after AngularJS has bootstrapped itself in the current document.

Then, you can call it inside a controller, or create a service with it so it is reusable inside your application.

IF, there is a resource that is supposed to load after the application, you can either load the script in the page or you can lazy load it.

For an Angular modules, you would need to use something similar to this.

https://github.com/ocombe/ocLazyLoad

For an external library, it will be best to use $scriptJS as the actual loading library, it also does AMD for you, it is really good. https://github.com/ded/script.js

Upvotes: 2

Related Questions