How to run Angular function on document ready?

How to run AngularJS function once the document is ready. Till now we used most famous JAVASCRIPT framework name is “jQuery”. The jQuery is open source framework. We can write all the jQuery functions on “document ready” so once all document is loaded then after running the jQuery code.

You all know how we can write the document ready on jQuery like below


        // Write the jQuery function here
        alert("Document Ready");


Above you can see how we write the document ready method on jQuery. We can write same document ready on AngularJs. So the function is run after all the js file is loaded. let’s see how we can write AngularJs function on document ready.

angular.module('MyApp', [])
    .controller('MyCtrl', [function() {
        angular.element(document).ready(function () {
            // write javascript/jQuery code here
            document.getElementById('message').innerHTML = 'Document Ready';

We see how we can write the javascript/jquery code on document ready using AngularJs APP. it’s too easy to write the document ready on AngularJs.

If you face any issue after using this code please write comment below.