0
votes

I want to async download angular script in my application and when it loads, I want to manually bootstrap the application. When I try to do this an error is thrown

Failed to instantiate module wt due to: Error: [$injector:modulerr] http://errors.angularjs.org/1.4.5/$injector/modulerr?p0=y...) at Error (native) at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:6:416 at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:38:98 at n (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:7:322) at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:37:180) at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:37:349 at n (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:7:322) at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:37:180) at eb (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:40:435) at d (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:19:381

My sample code is like

window.onload = function(){
  app = angular.module('wt', ['ngRoute']);
  app.config(function ($routeProvider,$locationProvider) {
      $routeProvider
          .when('/', {
              controller: 'homeController',
              templateUrl: 'template/home.html?ver='+file_version
          })
          .otherwise({ redirectTo: '/'});
      $locationProvider.html5Mode(true);
  });
  angular.module('wt').controller('homeController', function(){alert('Hello World');});
  angular.bootstrap(document, ['wt']);
}; 

And for script tag i am using

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js" async></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular-route.min.js" async defer></script>

Can someone help me figure out what I am doing wrong here?

1

1 Answers

0
votes

If you want to display the DOM before executing the Angular stuff, you could just put your scripts right before </body>