Angularjs 模块工厂模式:$inj未知提供程序:productResourceProvider
努力使工厂模式与angular和$resource一起工作。我好像犯了个错误 错误:[$injector:unpr]未知提供程序:productResourceProviderAngularjs 模块工厂模式:$inj未知提供程序:productResourceProvider,angularjs,Angularjs,努力使工厂模式与angular和$resource一起工作。我好像犯了个错误 错误:[$injector:unpr]未知提供程序:productResourceProvider 似乎您忘记调用工厂的函数了,在它的末尾添加了()。由于未调用该模块,因此该模块未声明为Angular,因此会出现未知提供程序错误: (function () { 'use strict'; angular .module('common.services')
似乎您忘记调用工厂的函数了,在它的末尾添加了
()
。由于未调用该模块,因此该模块未声明为Angular,因此会出现未知提供程序
错误:
(function () {
'use strict';
angular
.module('common.services')
.factory('productResource',
['$resource',
'appSettings',
productResource])
function productResource($resource, appSettings)
{
return $resource(appSettings.serverPath + '/api/products/:id');
}
})();
代码看起来不错..你忘了在你的页面中添加
common.services.js
吗?刚刚添加了html-我想我的脚本加载顺序还可以吗?
(function (){
'use strict';
angular
.module('common.services',
['ngResource'])
.constant('appSettings',
{
serverPath: "http://localhost:32642"
});
})();
(function () {
'use strict';
angular
.module('common.services')
.factory('productResource',
['$resource',
'appSettings',
productResource])
function productResource($resource, appSettings)
{
return $resource(appSettings.serverPath + '/api/products/:id');
}
})
(function () {
"use strict";
angular
.module("sampleapp")
.controller("ProductListCtrl",
['productResource', ProductListCtrl]);
function ProductListCtrl(productResource) {
var vm = this;
productResource.query(function (data)
{
vm.products = data;
});
}
}());
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Acme Product Management</title>
<!-- Style sheets -->
<link href="Content/bootstrap.css" rel="stylesheet" />
</head>
<body ng-app="sampleapp">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<div class="navbar-brand">Acme Product Management</div>
</div>
</div>
</nav>
<div class="container">
<div ng-include="'app/products/productListView.html'"></div>
</div>
<!-- Library Scripts -->
<script src="scripts/angular.js"></script>
<script src="scripts/angular-resource.js"></script>
<!-- Application Script -->
<script src="app/app.js"></script>
<!-- Services -->
<script src="common/common.services.js"></script>
<script src="common/productResource.js"></script>
<!-- Product Controllers -->
<script src="app/products/productListCtrl.js"></script>
</body>
</html>
(function () {
'use strict';
angular
.module('common.services')
.factory('productResource',
['$resource',
'appSettings',
productResource])
function productResource($resource, appSettings)
{
return $resource(appSettings.serverPath + '/api/products/:id');
}
})();