我坚持这一点,我阅读了有关它的所有内容,但我无法弄清楚,我在使用ng-app之前声明了我的<script>
app.js但仍然出现了这个错误:< / p>
由于以下原因无法实例化模块应用
[$ injector:nomod]模块'app'不可用!你要么拼错了 模块名称或忘记加载它。如果注册模块,请确保 您将依赖项指定为第二个参数。
该错误仅出现在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();
}
}
};
});
答案 0 :(得分:1)
尝试将此处的反斜杠更改为斜杠
<script src="js\app.js"></script>
到
<script src="js/app.js"></script>
这可能会让您的浏览器失效。