Michael
Michael

Reputation: 13616

Why do I get dependency error?

I am working on my angularjs tutorial.

Here module definition:

(function () {
    "use strict";
    var myApp = angular.module("sensorManagement",[]);
}());

Here is resource definition: (function () { "use strict";

angular.module("sensorManagement").factory("GetSensorDataResource",
                                        ["$resource",
                                         "ngResource",
                                         GetSensorDataResource])

    function GetSensorDataResource($resource) {
           return $resource("http://localhost:7486/api/Sensor/:id")
    }
}());

Here is controller definition:

(function () {
    "use strict";
    angular.module("sensorManagement").controller("SensorDataManagement",
                                                  ["GetSensorDataResource",
                                                  SensorDataManagement]);

    function SensorDataManagement(GetSensorDataResource) {
        var vm = this;

        GetSensorDataResource.query(function (data) {
            vm.sensorData = data;
        });
    }
})();

All function defined in separate files.In this order I call the files:

,

But when I run the example I get this error:

    Error: [$injector:unpr] Unknown provider: $resourceProvider <- $resource <- GetSensorDataResource
http://errors.angularjs.org/1.4.1/$injector/unpr?p0=%24resourceProvider%20%3C-%20%24resource%20%3C-%20GetSensorDataResource
    at REGEX_STRING_REGEXP (angular.js:68)
    at angular.js:4255
    at Object.getService [as get] (angular.js:4402)
    at angular.js:4260
    at getService (angular.js:4402)
    at Object.invoke (angular.js:4434)
    at Object.enforcedReturnValue [as $get] (angular.js:4296)
    at Object.invoke (angular.js:4443)
    at angular.js:4261
    at getService (angular.js:4402)

Any idea why I get the error?And how to solve it?

Upvotes: 0

Views: 41

Answers (1)

user1364910
user1364910

Reputation:

You need to include angular-resource.

ngResource docs

angular.module('sensorManagement', ['ngResource']);

Without loading the script and injecting the ngResource module into your own module, you won't have access to $resource or $resourceProvider as it is not included in the angular core.

Upvotes: 1

Related Questions