I am working on my angularjs tutorial.
我正在研究我的angularjs教程。
Here module definition:
这里模块定义:
(function () {
"use strict";
var myApp = angular.module("sensorManagement",[]);
}());
Here is resource definition: (function () { "use strict";
这是资源定义:(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?
知道我为什么会得到错误吗?如何解决?
1 个解决方案
#1
1
You need to include angular-resource
.
您需要包含角度资源。
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.
在不加载脚本并将ngResource模块注入到您自己的模块中的情况下,您将无法访问$ resource或$ resourceProvider,因为它未包含在angular core中。
#1
1
You need to include angular-resource
.
您需要包含角度资源。
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.
在不加载脚本并将ngResource模块注入到您自己的模块中的情况下,您将无法访问$ resource或$ resourceProvider,因为它未包含在angular core中。