我已經在AngularJS上做了一個測試應用程序,現在我正在嘗試與咖啡有點不同。問題是,它給了我這樣的錯誤:AngularJS with Coffeescript
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(因爲早些時候我不知道這件事情),並委派他爲我做的一切:)但仍thx爲您的答案。您可以將其添加到您的答案,所以我會接受它作爲完整的答案:) – 2014-11-26 09:57:59