在角度脚本标记中使用异步时手动引导角度

时间:2022-12-06 10:59:27

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

由于以下原因无法实例化模块wt:错误:[$ injector:modulerr] http://errors.angularjs.org/1.4.5/$injector/modulerr?p0 = y ...)错误(本机)位于https: //ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:6:416,网址为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)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)g(https://ajax.googleapis.com/ajax /libs/angularjs/1.4.5/angular.min.js:37:180)在eb(https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:40: 435)在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


0  

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

如果你想在执行Angular之前显示DOM,你可以把你的脚本放在 之前

#1


0  

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

如果你想在执行Angular之前显示DOM,你可以把你的脚本放在 之前