我收到错误错误:[$ injector:unpr]未知提供程序:$ resourceProvider <-$ resource <-productResource

时间:2019-06-05 07:02:30

标签: angularjs ngresource

Chrome控制台出现错误:

  

错误:[$ injector:unpr]未知提供程序:$ resourceProvider <-   $ resource <-p roductResource,

我已经检查了角度资源,打赌看起来还可以。

var app = angular.module('productManagement', ['common.service']);




angular
    .module("common.services",
        ["ngResource"])
    .constant("appSettings",
        {
            serverPath: "http://localhost:49896/"
        });


angular.module("common.service", []).
    factory("productResource", ["$resource",
        "appSettings",
        productResource]);


function productResource($resource, appSettings) {
    return $resource(appSettings.serverPath + "/api/products/:sku");


angular
    .module("productManagement")
    .controller("productListCtrl",
        productListCtrl);

function productListCtrl(productResource) {
    var vm = this;

    productResource.query(function (data) {
        vm.products = data;
    });

1 个答案:

答案 0 :(得分:0)

您的模块引用位于app变量中

var app = angular.module('productManagement', ['common.service']);

您应该这样做

app.module("productManagement")
    .controller("productListCtrl",
        productListCtrl);

function productListCtrl(productResource) {
    var vm = this;

    productResource.query(function (data) {
        vm.products = data;
    });