2014-01-31 69 views
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但我得到了同样的问题。

+0

您是否包含'factToDo'定义的js文件? –

+0

@IgorMalyk谢谢你的问题 – AAWaheed

回答

1

确保包含'factToDo'的文件包含在您的应用中。

为了方便开发并避免将来出现这样的问题,请尝试使用Grunt任务运行器连接您的所有代码并将其作为一个文件包含在其中。

This tutorial似乎足以开始使用Grunt和文件连接。

相关问题