我正在開發一個使用angularJS的簡單Web應用程序,而且我遇到了無法解決的問題。運行我的網站,我得到這個錯誤控制檯:AngularJS:模塊'App'不可用!您拼錯模塊名稱或忘記加載它
Uncaught 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.
但我敢肯定,我沒拼錯模塊名稱或忘了加載它。這裏是我的代碼:
var App = angular.module('App', ['ngRoute', 'ngMaterial', 'ui-notification', 'ngFileUpload']);
App.run(['$rootScope', '$location', function($rootScope, $location) {
console.log("TEST");
}]);
App.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
// TODO: routing
}]);
App.factory('file-uploader', ['Upload', function(Upload) {
var uploadFile = function(file, callback) {
var uploader;
uploader = Upload.upload({
url: 'SERVER URL' + '/upload-file',
data: {
image: file
}
});
uploader.then(function(fileData) {
return callback(null, fileData);
});
uploader.catch(function(error) {
return callback(error, null);
});
};
return uploadFile;
}]);
這是我的index.html:
<!DOCTYPE html>
<html ng-app="App">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
<meta name="description" content="">
<meta name="author" content="AUTHOR">
<title>PROJECT NAME | Login</title>
<link rel="stylesheet" href="/bower_components/angular-material/angular-material.css">
<link rel="stylesheet" href="/bower_components/angular-ui-notification/dist/angular-ui-notification.min.css">
<link rel="stylesheet" href="css/main.css" type="text/css">
</head>
<body ng-class="location" ng-cloak>
<div ng-view></div>
<script defer src="/bower_components/angular/angular.js"></script>
<script defer src="/bower_components/angular-route/angular-route.js"></script>
<script defer src="/bower_components/angular-aria/angular-aria.js"></script>
<script defer src="/bower_components/angular-animate/angular-animate.js"></script>
<script defer src="/bower_components/angular-messages/angular-messages.js"></script>
<script defer src="/bower_components/angular-ui-notification/dist/angular-ui-notification.min.js"></script>
<script defer src="/bower_components/angular-material/angular-material.js"></script>
<script defer src="/bower_components/jquery/dist/jquery.js"></script>
</body>
</html>
而且我已經安裝了所有與涼亭包...
是否有人可以告訴我哪裏是問題,我該如何解決它?
你有沒有在'ng-app =「App」'的HTML文件的某個地方包含應用程序? – thepio
這個清單可能有所幫助:http://stackoverflow.com/a/26797874/930170 –
@thepio當然,在我的HTML我有html(ng-app =「應用程序」) –