【发布时间】:2017-05-30 12:18:32
【问题描述】:
我已经在 AngularJS 中完成了一个测试应用程序,现在我正在尝试一些不同的和咖啡。问题是,它给了我这样的错误:
Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$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.
我不明白,为什么它看不到我的应用模块。这是我的代码:
index.html
<!doctype html>
<html lang="en" ng-app="app">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" href="css/app.css">
<script src="bower_components/jquery/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-animate/angular-animate.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="coffee/app.coffee" type="text/coffeescript" ></script>
<script src="coffee/controllers.coffee" type="text/coffeescript"></script>
</head>
<body>
<div class="view-container">
<div ng-view></div>
</div>
</body>
</html>
app.coffee
app = angular.module 'app', [
'ngRoute'
'commentController'
]
app.config [ '$routeProvider',
($routeProvider) ->
$routeProvider.
when('/title', {
templateUrl: 'templates/title.html'
controller: 'CommentListCtrl'
}).
otherwise({
redirectTo: '/title'
})
]
还有 controllers.coffee:
commentController = angular.module 'commentController', []
commentController.controller 'CommentListCtrl', [ '$scope',
($scope) ->
$scope.hello = "HELLO!"
]
【问题讨论】:
-
好吧,我用另一种方式做到了。安装了yeoman(因为之前我不知道这件事)并委托他为我做所有事情:)但仍然感谢您的回答。您可以将其添加到您的答案中,所以我会接受它作为完整答案:)
标签: javascript angularjs coffeescript