Eagle1
Eagle1

Reputation: 810

can't inject my custom module (provider error)

I'm trying to write my own module and then inject it into my application

This is the code of the module:

angular.module('GlobalUtilsFunctionsCheckInDB',['ngResource'])

// --------------------------------------------------- data services  ------------------------------------------------

.service('GlobalUtilsFunctionsCheckInDBdataService',['$http',function($http){

    this.getTree = function (dimension) {
            return $http({method:'POST',data:{dimensionpassed:dimension},url:Routing.generate('_NRtworks_globalUtilsFunctions_checkInDB')});
        };

}])

// --------------------------------------------------- METHODS  ------------------------------------------------

.factory('GlobalUtilsFunctionsCheckInDBMethods', function () {
    return{
        // Util for finding an object by its 'id' property among an array
        test:function test(object) 
        {
            console.log(object);
        }
    };
});

now in another js file, I have my application defined like this:

var treeView = angular.module('treeView', ['ngResource','xeditable','ui.tree','ui.router','GlobalUtilsFunctionsCheckInDB']);

and then I would like to inject my module into a controller of this app, defined like this:

treeView.controller('fullEdit',['$scope','$stateParams','utils','$state','reUsableData','$filter', 'GlobalUtilsFunctionsCheckInDB',function ($scope,$stateParams,utils,$state,reUsableData,$filter,GlobalUtilsFunctionsCheckInDBMethods)
{ GlobalUtilsFunctionsCheckInDB.test("show me"); };

the error I get is: Error: [$injector:unpr] Unknown provider: GlobalUtilsFunctionsCheckInDBProvider <- GlobalUtilsFunctionsCheckInDB http://errors.angularjs.org/1.2.28/$injector/unpr?p0=GlobalUtilsFunctionsCheckInDBProvider%20%3C-%20GlobalUtilsFunctionsCheckInDB

the load order is: angular, globalutils.js and then treeview.js

What do I do wrong ?

Upvotes: 0

Views: 327

Answers (1)

Shripal Soni
Shripal Soni

Reputation: 2448

In controller, you are injecting module instead of factory.

In controller dependency injection, change

treeView.controller('fullEdit',['$scope','$stateParams','utils','$state','reUsableData','$filter', 'GlobalUtilsFunctionsCheckInDB',function ($scope,

to

treeView.controller('fullEdit',['$scope','$stateParams','utils','$state','reUsableData','$filter', 'GlobalUtilsFunctionsCheckInDBMethods',function ($scope,

Upvotes: 1

Related Questions