错误:[$ injector:unpr]未知提供者:GetOrdersProvider< - GetOrders< - OrderController

时间:2017-04-13 10:37:48

标签: javascript angularjs asp.net-mvc asp.net-web-api

我想在不同的网址上发布帖子操作。当我试着写不同的工厂时,我想它可以识别另一家工厂。

Service.js

var app = angular.module("ServiceApp", ["ngResource"]);

    app.factory('GetPortfolios', function ($resource) {
    return $resource("http://localhost:61347/api/PortfolioManager/GetPortfolios/", {}, {
    });

    app.factory('GetOrders', function ($resource) {
        return $resource("http://localhost:61347/api/PortfolioManager/GetPortfolioOrders/");
    });
});

App.js

var app = angular.module("UiApp", ["ServiceApp"]);

app.controller("PortFolioController", function ($scope, GetPortfolios) {
    $scope.Portfolios = GetPortfolios.query({ pmid: 2 });
    console.log($scope.Portfolios);
});

app.controller("OrderController", function ($scope, GetOrders) {
    $scope.Orders = GetOrders.query({ id: 25 });
    console.log(Orders);
});

1 个答案:

答案 0 :(得分:1)

在Service.js内,第一个工厂缺少结束 }) paranthesis,请检查更新后的Service.js

var app = angular.module("ServiceApp", ["ngResource"]);

app.factory('GetPortfolios', function ($resource) {
    return $resource("http://localhost:61347/api/PortfolioManager/GetPortfolios/", {}, {});
});

app.factory('GetOrders', function ($resource) {
    return $resource("http://localhost:61347/api/PortfolioManager/GetPortfolioOrders/");
});