我被困在这个问题上,我读了所有相关内容,但我无法弄清楚,我声明我的 <script>
app.js 在使用 ng-app 之前仍然收到此错误:
无法实例化模块应用程序,原因是:
[$injector:nomod] Module 'app' 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.
该错误仅出现在 Firefox 上。
HTML:
<html lang="en-US">
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<link rel="stylesheet" type ="text/css" href="css\bootstrap.min.css"/>
<link rel="stylesheet" type ="text/css" href="css\component.css"/>
<link rel="stylesheet" type ="text/css" href="css\app.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-animate.js"></script>
<script type="text/javascript" src="js\modernizr.custom.js"></script>
<script type="text/javascript" src="js\ui-bootstrap-tpls-1.2.4.min.js"></script>
<script src="js\app.js"></script>
</head>
<body ng-app="app">>
<div class="top row">
<top-header></top-header>
<home-carousel></home-carousel>
</div>
</body>
</html>
js:
var app = angular.module('app', ['ngAnimate', 'ui.bootstrap']);
app.directive('topHeader', function() {
return {
restrict: 'E',
templateUrl: 'topHeader.html',
controller: function ($scope, $window) {
name = $window.location.pathname;
n = name.lastIndexOf("/");
name = name.substring(n + 1);
if (name === "index.html" || name === "")
$scope.current = '1';
else if (name === "resume.html")
$scope.current = '2';
else if (name === "projects.html")
$scope.current = '3';
}
};
});
app.directive('homeCarousel', function() {
return {
restrict: 'E',
templateUrl: 'homeCarousel.html',
controller: function ($scope)
{
$scope.myInterval = 5000;
$scope.noWrapSlides = false;
$scope.active = 0;
var slides = $scope.slides = [];
var currIndex = 0;
$scope.addSlide = function()
{
slides.push(
{
image: "image" + currIndex+ ".jpg",
id: currIndex++
});
};
for (var i = 0; i < 3; i++)
{
$scope.addSlide();
}
}
};
});
最佳答案
尝试将这里的反斜杠改为斜杠
<script src="js\app.js"></script>
至
<script src="js/app.js"></script>
这可能会导致您的浏览器无法正常运行。
关于javascript - $injector :nomod Module 'app' is not available! 仅限 Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36059145/