简体   繁体   English

错误:[$ injector:unpr]未知提供者:

[英]Error: [$injector:unpr] Unknown provider:

File structure: 文件结构:

在此处输入图片说明

app.js app.js

(function () {
    "use strict";

    var app = angular.module("app", ["common.services", "ngRoute", "ngResource"])

    app.config(function ($routeProvider) {
        $routeProvider
        // route for the home page
        //.when('/', {
        //    controller: 'mainController',
        //    templateUrl: 'app/linkPages/home.html'
        //})

        // route for the about page
        //.when('/about', {
        //    controller: 'aboutController',
        //    templateUrl: 'app/linkPages/about.html'
        //})

        // route for the contact page
        //.when('/contact', {
        //    controller: 'contactController',
        //    templateUrl: 'app/linkPages/contact.html'
        //})

        .when('/', {
            controller: 'AgencyListCtrl',
            templateUrl: 'app/agencies/agencyListView.html'
        })

        //.when('/agencyEditView', {
        //    controller: 'AgencyEditCtrl',
        //    templateUrl: 'app/agencies/agencyEditView.html'
        //});

    });

    // create the controller and inject Angular's $scope
    app.controller('mainController', function ($scope) {
        // create a message to display in our view
        $scope.message = 'This is the Main controller page';
    });

    app.controller('aboutController', function ($scope) {
        $scope.message = 'This is the about controller page';
    });

    app.controller('contactController', function ($scope) {
        $scope.message = 'This is the contact controller page';
    });

}());

common.services.js common.services.js

(function () {
    "use strict";

    angular
        .module("common.services",
                    ["ngResource"])//common.services

        .constant("appSettings",
        {
            serverPath: "http://localhost:53403/" // will replace production server url 
        });
}());

agencyResource.js agencyResource.js

(function () {

    "use strict";

    angular.module("app")//common.services
        .factory("agencyResource"
                ["ngResource", "$resource",
                 "appSettings",
                    agencyResource])

    function agencyResource($resource, appSettings) {
        return $resource(appSettings.serverPath + "/api/v1/agencies/:id", null,
            {
                'update': { method: 'PUT' },
            });
    }

}());

agencyListCtrl.js agencyListCtrl.js

(function () {

    "use strict";

    angular
        .module("app")
        .controller("AgencyListCtrl",
                    ["agencyResource",
                     AgencyListCtrl]);

    function AgencyListCtrl(agencyResource) {
        var vm = this;

        //agencyResource.query({ $filter: "contains(Abbr,'IOT')" },
        //    function (data) {
        //        vm.agencies = data;

        //        console.log(result);
            //})

        agencyResource.query({},
            function (data) {
                vm.agencies = data;

        console.log(result);
    })

}
}());

ERROR: 错误:

HTML1300: Navigation occurred. HTML1300:发生导航。 index.html Error: [$injector:unpr] Unknown provider: agencyResourceProvider <- agencyResource <- AgencyListCtrl http://errors.angularjs.org/1.5.9/ $injector/unpr?p0=agencyResourceProvider%20%3C-%20agencyResource%20%3C-%20AgencyListCtrl at Anonymous function ( http://localhost:61924/Scripts/angular.js:4554:13 ) at getService ( http://localhost:61924/Scripts/angular.js:4707:11 ) at Anonymous function ( http://localhost:61924/Scripts/angular.js:4559:13 ) at getService ( http://localhost:61924/Scripts/angular.js:4707:11 ) at injectionArgs ( http://localhost:61924/Scripts/angular.js:4731:9 ) at instantiate ( http://localhost:61924/Scripts/angular.js:4774:7 ) at $controller ( http://localhost:61924/Scripts/angular.js:10533:7 ) at link ( http://localhost:61924/Scripts/angular-route.js:1056:9 ) at Anonymous function ( http://localhost:61924/Scripts/angular.js:1258:11 ) at invokeLinkFn ( http://localhost:61924/Scripts/angular.js:10095:9 ) index.html错误:[$ injector:unpr]未知提供程序:agencyResourceProvider <-agencyResource <-AgencyListCtrl http://errors.angularjs.org/1.5.9/ $ injector / unpr?p0 = agencyResourceProvider%20%3C-%20agencyResource在getService( http:// localhost:61924 / Scripts / angular.js:4707:11 )的匿名函数( http:// localhost:61924 / Scripts / angular.js:4554:13 )处为%20%3C-%20AgencyListCtrl在匿名功能( HTTP://本地主机:61924 /脚本/ angular.js:4559:13 )在的getService( HTTP://本地主机:61924 /脚本/ angular.js:4707:11 )在injectionArgs( HTTP://在$ controller( http:// localhost:61924 / Scripts / angular )实例化( http:// localhost:61924 / Scripts / angular.js:4774:7 )时访问localhost:61924 / Scripts / angular.js:4731:9.js:10533:7 )的链接( http:// localhost:61924 / Scripts / angular-route.js:1056:9 )的匿名函数( http:// localhost:61924 / Scripts / angular.js:1258: 11 )在invokeLinkFn( http:// localhost:61924 / Scripts / angular.js:10095:9

I am not sure weather I have injected everything right here? 我不确定天气是否在这里注入了所有东西? Any help would be appreciated. 任何帮助,将不胜感激。 This is my first angular app so I am a little green. 这是我的第一个有角度的应用程序,所以我有点绿色。 Stack Overflow is telling me I have to type more details but the code post are pretty self explanatory. Stack Overflow告诉我我必须输入更多详细信息,但是代码后的内容很容易说明。 I 一世

The answer is that I was declaring ngResource in the agencyResource.js file. 答案是,我在agencyResource.js文件中声明了ngResource。 It should look like this. 它应该看起来像这样。 MY BAD. 我的错。

agencyResource.js agencyResource.js

 (function () { "use strict"; angular.module("common.services")//common.services .factory("agencyResource", [ "$resource", "appSettings", agencyResource ]) function agencyResource($resource, appSettings) { return $resource(appSettings.serverPath + "/api/v1/agencies/:id", null, { 'update': { method: 'PUT' }, }); } }()); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM