Angular DI未知提供程序错误

时间:2013-08-06 10:12:17

标签: angularjs dependency-injection

我正在尝试将DI与Angular一起使用,但是因为我收到错误而被卡住了

Error: Unknown provider: dataServiceProvider <- dataService

这是我的Main.js:

var app = {};

app.angularModule = angular.module('TestWeb', []);

app.angularModule.value("breeze", window.breeze);
app.angularModule.value("toastr", window.toastr);

以下是我的记录器的一部分:

app.angularModule.factory('logger', function (toastr, $window) {

    toastr.options.timeOut = 2000; // 2 second toast timeout
    toastr.options.positionClass = 'toast-bottom-right';

    var logger = {
        error: error,
        info: info,
        success: success,
        warning: warning,
        log: log // straight to console; bypass toast
    };

以下是我的DataService的一部分:

app.angularModule.factory = ('dataService', function (breeze, logger) {

    breeze.config.initializeAdapterInstance("modelLibrary", "backingStore", true);


    var mbservice = new breeze.DataService({
        serviceName: "http://localhost:23758/api/",
        hasServerMetadata: false,
    });

    var manager = new breeze.EntityManager({ dataService: mbservice });

    manager.enableSaveQueuing(true);

    var dataService = {
        getAll: getAll,
        createItem: createItem,
        saveChanges: saveChanges,

    };

这是我的样本控制器的一部分:

app.angularModule.controller('testCtrl', function($scope, breeze, dataService, logger) {

    $scope.items = [];

    $scope.getAll = function() {
        dataService.getAll("tests")
            .then(querySucceeded)
            .fail(queryFailed);
    };

    $scope.getAll();

这是html的一部分:

             

这是完整的错误

Error: Unknown provider: dataServiceProvider <- dataService
    at Error (<anonymous>)
    at http://localhost:7122/Scripts/angular/angular.js:2734:15
    at Object.getService [as get] (http://localhost:7122/Scripts/angular/angular.js:2862:39)
    at http://localhost:7122/Scripts/angular/angular.js:2739:45
    at getService (http://localhost:7122/Scripts/angular/angular.js:2862:39)
    at invoke (http://localhost:7122/Scripts/angular/angular.js:2880:13)
    at Object.instantiate (http://localhost:7122/Scripts/angular/angular.js:2914:23)
    at http://localhost:7122/Scripts/angular/angular.js:4805:24
    at http://localhost:7122/Scripts/angular/angular.js:4384:17
    at forEach (http://localhost:7122/Scripts/angular/angular.js:137:20) angular.js:5754
(anonymous function) angular.js:5754

注意:

我正在使用DI:link关注微风样本ToDO Angular,我正在使用相同的DI。但我得到错误,不知道为什么。

1 个答案:

答案 0 :(得分:2)

请注意您对记录器工厂和数据服务工厂的定义之间的区别:

app.angularModule.factory('logger', function (toastr, $window) {

VS

app.angularModule.factory = ('dataService', function (breeze, logger) {

数据服务工厂的定义方式与您对记录器工厂的定义方式相同。