2016-09-30 62 views
0

当我尝试使用属性async我的脚本标记没有定义,我不断收到此错误:角使用异步属性

Uncaught ReferenceError: angular is not defined

Module 'app.main' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

当寻找在docs,我看到来引导它推荐手工,所以我这样做:

<script async type="text/javascript" src="dist/js/angular.min.js"></script> 
    <script async type="text/javascript" src="dist/js/app.min.js"></script> 

    <script async> 
     angular.element(document).ready(function() { 
      angular.bootstrap(document, ['app.main']); 
     }); 
    </script> 
</body> 

I know async should be used when the script is at the beggining of the page, but in both situations I had the same error.

正如你所看到的,我想在结束手动引导我的应用程序。我也尝试在文件末尾使用app.min.js文件中的相同代码,但两种方案都给了我相同的结果。

如果我删除attr异步,一切恢复正常,再次工作,但我该如何解决这个问题?

+0

你为什么要他们来加载异步?除非使用加载管理器,否则不能控制这3个脚本的执行顺序。显然,最后一个不需要时间下载,并且可能会在angulr被定义之前先执行 – charlietfl

回答

1

只要你知道

Note: The async attribute is only for external scripts (and should only be used if the src attribute is present). 

谢谢:)