问题描述
我遇到了一个问题,即我的AngularJS网页有时无法正确加载。发生这种情况时,相应控制器中的代码不会运行。它很少发生。我怀疑这可能是由于AngularJS文件的加载顺序。也许还有其他可能的原因。如果你能想到,请提醒我。下面是我的代码,显示了html页面的加载顺序;
< script src =lib / angular / angular.min的.js>< /脚本>
< script src =lib / angular / angular-route.min.js>< / script>
< script src =js / app.js>< / script>
< script src =js / services.js>< / script>
< script src =js / controllers.js>< / script>
< script src =js / filters.js>< / script>
< script src =js / directives.js>< / script>
< script src =vendor / dialogs.min.jstype =text / javascript>< / script>
< script src =lib / angular / angular-sanitize.min.js>< / script>
< script src =vendor / angular-translate.min.js>< / script>
< link href =vendor / dialogs.css =stylesheet>
有什么不对吗?
< script src =lib / angular / angular。 min.js>< /脚本>
< script src =lib / angular / angular-route.min.js>< / script>
< script src =vendor / dialogs.min.jstype =text / javascript>< / script>
< script src =lib / angular / angular-sanitize.min.js>< / script>
< script src =vendor / angular-translate.min.js>< / script>
之后加载你的控制器,服务,过滤器,指令
< script src =js / services.js>< / script>
< script src =js / controllers.js>< / script>
< script src =js / filters.js>< / script>
< script src =js / directives.js>< / script>
最后,现在你可以加载你的app init文件
< script src =js / app.js>< / script>
I encountered a problem where my AngularJS webpages don't load properly sometimes. When this happens, the code in the corresponding controller does not run. It only happens rarely. I suspect that this could be due to the loading order of AngularJS files. Perhaps there are other possible causes. Please alert me if you can think of any. Below is my code showing the loading order of the html page;
<script src="lib/angular/angular.min.js"></script>
<script src="lib/angular/angular-route.min.js"></script>
<script src="js/app.js"></script>
<script src="js/services.js"></script>
<script src="js/controllers.js"></script>
<script src="js/filters.js"></script>
<script src="js/directives.js"></script>
<script src="vendor/dialogs.min.js" type="text/javascript"></script>
<script src="lib/angular/angular-sanitize.min.js"></script>
<script src="vendor/angular-translate.min.js"></script>
<link href="vendor/dialogs.css" rel="stylesheet">
Is there anything wrong?
First Load angular library:
<script src="lib/angular/angular.min.js"></script>
<script src="lib/angular/angular-route.min.js"></script>
<script src="vendor/dialogs.min.js" type="text/javascript"></script>
<script src="lib/angular/angular-sanitize.min.js"></script>
<script src="vendor/angular-translate.min.js"></script>
After that load your controllers, services, filters, directives
<script src="js/services.js"></script>
<script src="js/controllers.js"></script>
<script src="js/filters.js"></script>
<script src="js/directives.js"></script>
Finally, now you can load your app init file
<script src="js/app.js"></script>
这篇关于加载AngularJS文件的正确顺序是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!