0

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 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

5 Comments

But this does not fulfill my desire to async load angular script
How do you load your script?
async attribute in script tag
Is your sample code also loaded from an external file?
Do you have an example of the tag you are using to load it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.