title: How to run the service on page load
body: <p>I have the function inside service in angular module but how do I run the service on page load. I am not using any controller here</p>
  
  <p>Code:</p>
  
  <pre><code>var app = angular.module("myTmoApppdl", [])
          .service('populatePageObjsService', function () {
  
              var self = this;
  
              //digitalData is a global object
              self.populatePage = function (digitalData) {
                  var dataPageObject = document.getElementById('metaJson').getAttribute("data-pageObject");
                  var jsonPageObject = JSON.parse(dataPageObject);
  
                  for (var key in jsonPageObject.page.pageInfo) {
                      var value = jsonPageObject.page.pageInfo[key];
                      if (digitalData.page.pageInfo.hasOwnProperty(key)) {
                          digitalData.page.pageInfo[key] = value;
                      }
                  }
                  console.log("Page data populated successfully: ", digitalData.page.pageInfo);
              }();
          });
  </code></pre>
  
  <p>I tried using the <code>()</code> after function but it didn't execute the function</p>
  
  <p>Update:</p>
  
  <pre><code>var app = angular.module("myTmoApppdl", []).run(function () {
      app.service('populatePageObjsService', function () {
          var self = this;
          self.populatePage = function (digitalData) {
              var dataPageObject = document.getElementById('metaJson').getAttribute("data-pageObject");
              var jsonPageObject = JSON.parse(dataPageObject);
  
              for (var key in jsonPageObject.page.pageInfo) {
                  var value = jsonPageObject.page.pageInfo[key];
                  if (digitalData.page.pageInfo.hasOwnProperty(key)) {
                      digitalData.page.pageInfo[key] = value;
                  }
              }
              console.log("Page data populated successfully: ", digitalData.page.pageInfo);
          };
      });
  });
  </code></pre>