0
我正在使用yeoman角整堆生成器。試用MongoDB的ToDo項教程。 一切工作正常,即我能夠使用$ http.get從數據庫讀取。不過,我決定進一步創建一個工廠,以便我可以執行CURD。注入工廠時出現未知提供商錯誤
建立工廠後,我試圖把它注射,但得到的錯誤如下:
Error: [$injector:unpr] Unknown provider: factToDoProvider <- factToDo
http://errors.angularjs.org/1.2.6/$injector/unpr?p0=factToDoProvider%20%3C-NaNactToDo
at http://localhost:9000/bower_components/angular/angular.js:78:12
at http://localhost:9000/bower_components/angular/angular.js:3538:19
at Object.getService [as get] (http://localhost:9000/bower_components/angular/angular.js:3665:39)
at http://localhost:9000/bower_components/angular/angular.js:3543:45
at getService (http://localhost:9000/bower_components/angular/angular.js:3665:39)
at invoke (http://localhost:9000/bower_components/angular/angular.js:3687:13)
at Object.instantiate (http://localhost:9000/bower_components/angular/angular.js:3708:23)
at http://localhost:9000/bower_components/angular/angular.js:6758:28
at link (http://localhost:9000/bower_components/angular-route/angular-route.js:897:26)
at nodeLinkFn (http://localhost:9000/bower_components/angular/angular.js:6212:13)
Main.js控制器看起來像
'use strict';
angular.module('angularFsApp')
.controller('MainCtrl', function ($scope, $http, factToDo) {
$http.get('/api/awesomeThings').success(function(awesomeThings) {
$scope.awesomeThings = awesomeThings;
});
$http.get('/todo/todoItems').success(function(todoItems) {
$scope.todoItems = todoItems;
});
//$scope.newtodoItems = factToDo.getAllItems();
});
哪裏factToDo是我廠看起來像如下(待辦事項.js)
angular.module('angularFsApp')
.factory('factToDo', function() {
return {
getAllItems: function() {
return [
{description: 'Hello World 1', priority: '15'},
{description: 'Hello World 2', priority: '15'},
{description: 'Love for all', priority: '1500'}
];
}
}
});
我嘗試通過更改main.js中的代碼,如中所述如下
angular.module('angularFsApp')
.controller('MainCtrl', ['$scope', '$http', 'factToDo', function ($scope, $http, factToDo) {
以及我試圖Dan Wahlin但我得到了同樣的問題。
您是否包含'factToDo'定義的js文件? –
@IgorMalyk謝謝你的問題 – AAWaheed