Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 模块工厂模式:$inj未知提供程序:productResourceProvider_Angularjs - Fatal编程技术网

Angularjs 模块工厂模式:$inj未知提供程序:productResourceProvider

Angularjs 模块工厂模式:$inj未知提供程序:productResourceProvider,angularjs,Angularjs,努力使工厂模式与angular和$resource一起工作。我好像犯了个错误 错误:[$injector:unpr]未知提供程序:productResourceProvider 似乎您忘记调用工厂的函数了,在它的末尾添加了()。由于未调用该模块,因此该模块未声明为Angular,因此会出现未知提供程序错误: (function () { 'use strict'; angular .module('common.services')

努力使工厂模式与angular和$resource一起工作。我好像犯了个错误

错误:[$injector:unpr]未知提供程序:productResourceProvider
似乎您忘记调用工厂的函数了,在它的末尾添加了
()
。由于未调用该模块,因此该模块未声明为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');
    }

})();