我在尝试实施服务时遇到Error: [$injector:unpr] Unknown provider: LoginServiceProvider <- LoginService <- LoginController...
形式的错误。我是棱角分明的新人,怀疑我错过了一些明显的东西。我试过用非缩小的JS来查看错误,但没有什么看起来太有帮助。我已经检查了三次拼写,看了很多没有进展的例子。任何帮助或建议非常感谢。
完整错误
Error: [$injector:unpr] Unknown provider: LoginServiceProvider <- LoginService <- LoginController
http://errors.angularjs.org/1.6.3/$injector/unpr?p0=LoginServiceProvider%20%3C-%20LoginService%20%3C-%20LoginController
Stack trace:
minErr/<@http://localhost:8080/libs/angular/angular.js:66:12
createInjector/providerCache.$injector<@http://localhost:8080/libs/angular/angular.js:4789:19
getService@http://localhost:8080/libs/angular/angular.js:4944:32
createInjector/protoInstanceInjector<@http://localhost:8080/libs/angular/angular.js:4794:28
getService@http://localhost:8080/libs/angular/angular.js:4944:32
injectionArgs@http://localhost:8080/libs/angular/angular.js:4969:58
instantiate@http://localhost:8080/libs/angular/angular.js:5015:18
$controller@http://localhost:8080/libs/angular/angular.js:10877:18
ngViewFillContentFactory/<.link@http://localhost:8080/libs/angular- route/angular-route.js:1214:26
bind/<@http://localhost:8080/libs/angular/angular.js:1341:15
invokeLinkFn@http://localhost:8080/libs/angular/angular.js:10419:9
nodeLinkFn@http://localhost:8080/libs/angular/angular.js:9808:11
compositeLinkFn@http://localhost:8080/libs/angular/angular.js:9048:13
publicLinkFn@http://localhost:8080/libs/angular/angular.js:8913:30
lazyCompilation@http://localhost:8080/libs/angular/angular.js:9304:16
boundTranscludeFn@http://localhost:8080/libs/angular/angular.js:9091:16
controllersBoundTransclude@http://localhost:8080/libs/angular/angular.js:9858:20
update@http://localhost:8080/libs/angular-route/angular-route.js:1172:25
$RootScopeProvider/this.$get</Scope.prototype.$broadcast@http://localhost:8080/libs/angular/angular.js:18498:15
commitRoute/</<@http://localhost:8080/libs/angular-route/angular-route.js:734:19
processQueue@http://localhost:8080/libs/angular/angular.js:16843:37
scheduleProcessQueue/<@http://localhost:8080/libs/angular/angular.js:16887:27
$RootScopeProvider/this.$get</Scope.prototype.$digest@http://localhost:8080/libs/angular/angular.js:17982:15
$RootScopeProvider/this.$get</Scope.prototype.$apply@http://localhost:8080/libs/angular/angular.js:18280:13
done@http://localhost:8080/libs/angular/angular.js:12378:36
completeRequest@http://localhost:8080/libs/angular/angular.js:12604:7
requestLoaded@http://localhost:8080/libs/angular/angular.js:12532:9
app.js
angular.module('rateApp', [
'ngRoute',
'appRoutes',
'MainCtrl',
'LoginCtrl', 'LoginService'
]);
appRoutes.js
angular.module('appRoutes', []).config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider
// home page
.when('/', {
templateUrl: 'views/home.html',
controller: 'MainController'
})
// Login page
.when('/login', {
templateUrl: 'views/login.html',
controller: 'LoginController'
});
$locationProvider.html5Mode(true);
}]);
控制器/ LoginCtrl.js
angular.module('LoginCtrl', []).controller('LoginController', function($scope, LoginService) {
$scope.departments = LoginService.getAllDepartments();
$scope.faculties = LoginService.getAllFaculties();
});
服务/ LoginService.js
angular.module('LoginService', []).factory('Login', ['$http', function($http) {
return {
// Get all the known departments
getAllDepartments: function() {
return $http.get('/api/dept/all');
},
// Get all the known faculties
getAllFaculties: function() {
return $http.get('/api/faculties/all');
}
}
}]);
的index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<base href="/">
<title>App</title>
<!-- CSS -->
<link rel="stylesheet" href="libs/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="css/master.css">
<!-- custom styles -->
<!-- JS -->
<script src="libs/jquery/dist/jquery.js"></script>
<script src="libs/angular/angular.js"></script>
<script src="libs/angular-route/angular-route.js"></script>
<!-- ANGULAR CUSTOM -->
<script src="js/controllers/MainCtrl.js"></script>
<script src="js/services/LoginService.js"></script>
<script src="js/controllers/LoginCtrl.js"></script>
<script src="js/appRoutes.js"></script>
<script src="js/app.js"></script>
</head>
<body ng-app="rateApp" ng-controller="MainController">
<!-- HEADER -->
<div class="container">
<!-- ANGULAR DYNAMIC CONTENT -->
<div ng-view></div>
</div>
</body>
</html>
答案 0 :(得分:0)
您的控制器应该注入 Login
而不是 LoginService
,因为 LoginService
是一个模块
angular.module('LoginCtrl', []).controller('LoginController',function($scope, Login) {
$scope.departments = Login.getAllDepartments();
$scope.faculties = Login.getAllFaculties();
});
答案 1 :(得分:0)
更改
2017-03-13T04:33:33.358+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=4f14ca0711c7
2017-03-13T04:33:33.358+0000 I CONTROL [initandlisten] db version v3.4.2
2017-03-13T04:33:33.358+0000 I CONTROL [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
2017-03-13T04:33:33.358+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1t 3 May 2016
2017-03-13T04:33:33.358+0000 I CONTROL [initandlisten] allocator: tcmalloc
2017-03-13T04:33:33.358+0000 I CONTROL [initandlisten] modules: none
2017-03-13T04:33:33.358+0000 I CONTROL [initandlisten] build environment:
2017-03-13T04:33:33.358+0000 I CONTROL [initandlisten] distmod: debian81
2017-03-13T04:33:33.358+0000 I CONTROL [initandlisten] distarch: x86_64
2017-03-13T04:33:33.358+0000 I CONTROL [initandlisten] target_arch: x86_64
2017-03-13T04:33:33.358+0000 I CONTROL [initandlisten] options: {}
2017-03-13T04:33:33.363+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=478M,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-03-13T04:33:33.384+0000 E STORAGE [initandlisten] WiredTiger error (17) [1489379613:384669][1:0x7f1e6c4f5cc0], connection: /data/db/WiredTiger.wt: handle-open: open: File exists
2017-03-13T04:33:33.385+0000 I STORAGE [initandlisten] WiredTiger message unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.1
2017-03-13T04:33:33.386+0000 E STORAGE [initandlisten] WiredTiger error (1) [1489379613:386165][1:0x7f1e6c4f5cc0], connection: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
2017-03-13T04:33:33.386+0000 I - [initandlisten] Assertion: 28595:1: Operation not permitted src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 267
2017-03-13T04:33:33.387+0000 I STORAGE [initandlisten] exception in initAndListen: 28595 1: Operation not permitted, terminating
2017-03-13T04:33:33.387+0000 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-03-13T04:33:33.387+0000 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2017-03-13T04:33:33.387+0000 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-03-13T04:33:33.387+0000 I CONTROL [initandlisten] now exiting
2017-03-13T04:33:33.387+0000 I CONTROL [initandlisten] shutting down with code:100
至angular.module('appRoutes', [])
和
angular.module('appRoutes', ['LoginCtrl'])
至angular.module('LoginCtrl', ['LoginService'])
看起来依赖项(模块)未正确注入模块。