我在使用 Angular 应用程序时遇到问题。我正在使用凉亭。当我启动服务器时,有时会出现以下错误:
Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to: Error: [$injector:modulerr] Failed to instantiate module ui.router due to: Error: [$injector:nomod] Module 'ui.router' is not available! You either misspelled the modul......2)
然后我有时会收到此错误:
Uncaught SyntaxError: Unexpected identifier angular.js:573
Uncaught TypeError: Cannot read property 'module' of undefined angular-route.js:24
Uncaught SyntaxError: Unexpected token ILLEGAL angular-ui-router.js:455
Uncaught ReferenceError: angular is not defined ui-bootstrap-tpls-0.11.0.js:8
Uncaught ReferenceError: angular is not defined app.js:4
Uncaught ReferenceError: angular is not defined
有时 CSS 也无法完全加载,但不会出现控制台错误。其他时候它工作得很好。
这是我的代码设置
<body ng-app="myApp" class="ng-scope">
<div>
<div ui-view>
</div>
</div>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.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="js/create.js"></script>
<script src="js/view.js"></script>
<script src="js/header.js"></script>
<script src="js/form-service.js"></script>
<script src="js/form-directive.js"></script>
<script src="js/field-directive.js"></script>
<script src="js/jquery.dcjqaccordion.2.7.js"></script>
</body>
这是我的应用程序所在的 app.js
var myApp = angular.module('myApp', [
'ui.bootstrap.tabs',
'ui.bootstrap.accordion',
'ui.bootstrap.collapse',
/*
'$strap.directives',
*/
'ui.router',
'myApp.filters',
'myApp.services',
'myApp.directives',
'myApp.controllers'
]);
不太确定该做什么。我认为加载 Angular 然后在一段时间延迟后加载其他脚本可以修复它,但这行不通。
最佳答案
您的问题不是使用 .js 文件的绝对 URL。在每个路径前面包含一个 /
,它应该可以解决您的问题。例如更改:
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.js">
至
<script src="/bower_components/angular/angular.js"></script>
<script src="/bower_components/angular-route/angular-route.js"></script>
<script src="/bower_components/angular-ui-router/release/angular-ui-router.js">
对所有文件执行此操作。
关于javascript - Angular.js 仅加载一半时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25146646/