Tutorialsplane

AngularJs Call Function on Page Load


AngularJs Call Function on Page Load โ€“ There are many ways to call a function on page load in angularjs. You can use $window object to call a function on page. Here in this tutorial we are going to explain how you can call function on page load in angularjs. We will explain this with example and demo.


AngularJs Call Function on Page Load

You can call a function on page load simply using the $window.onload as below โ€“

AngularJs Call Function on Page Load: Example




 
  

  
<div ng-app="myApp">  
<div ng-controller="myController">  
</div>  
</div> 

  
      
                                                                                                                                                                                                                                                                                                                                                                            

Try it ยป

The above function will be called on page load. The above function will trigger a alert on page load and it will produce output something like this โ€“