Ошибка: [$ injector: unpr] Неизвестный провайдер: nxProvider <- nx <- adminController - PullRequest
0 голосов
/ 09 июля 2020

Я работаю над приложением AngularJS (v1.6), где получаю следующую ошибку. Я попытался перейти по предложенной ссылке (https://code.angularjs.org/1.6.5/docs/error/ $ injector / unpr? P0 = nxProvider% 20% 3 C -% 20nx% 20% 3 C -% 20adminController ), но это не сработало.

angular.js:14642 Error: [$injector:unpr] Unknown provider: nxProvider <- nx <- adminController
http://errors.angularjs.org/1.6.5/$injector/unpr?p0=nxProvider%20%3C-%20nx%20%3C-%20adminController
    at angular.js:116
    at angular.js:4826
    at Object.getService [as get] (angular.js:4981)
    at angular.js:4831
    at getService (angular.js:4981)
    at injectionArgs (angular.js:5006)
    at Object.instantiate (angular.js:5052)
    at $controller (angular.js:10975)
    at Object.<anonymous> (angular-ui-router.js:4203)
    at angular.js:1385 "<div ui-view="" class="ng-scope">"

Если я удалю инжектор nx, появится ошибка, связанная с поставщиком http. Error: [$injector:unpr] Unknown provider: httpProvider <- http <- adminService

Вот мой код admin.controller.js:

(function () {
    'use strict';
    angular.module('app').controller('adminController', adminController);
    adminController.$inject = ['$http', 'nx', '$q', '$rootScope', '$scope', 'adminService', '$state'];
        function adminController($http, nx, $q, $rootScope, $scope, adminService) {
               /** code here **/
        }
})();

и admin.service.js следующим образом:

(function () {
'use strict';
angular.module('app').factory('adminService', adminService);
adminService.$inject = ['http', 'enums', '$state'];
function adminService(http, enums, $state) {
    function get(req) {
        var request = {
            url: req.url,
            params: req.params || ''
        };
        return http.get(request).then(function (success) {
            return success;
        }, function (error) {
            if (error.status === -1) {
                location.href = MyappURL;
            }
            console.log(error);
           // $state.go("auth.sessionExpired");
            return error;
        });
    };

    function post(req) {
        var request = {
            url: req.url,
            params: req.params
        };
        return http.post(request).then(function (success) {
            return success;
        }, function (error) {
           // $state.go("auth.sessionExpired");
            return error;
        });
    };
    return {
        get: get,
        post: post
    }
};
})();

Заранее спасибо!

1 Ответ

0 голосов
/ 11 июля 2020

вам не хватает nx инъекции токена здесь: adminService.$inject = ['http', 'enums', '$state'];

Изменить на: adminService.$inject = ['nx', 'http', 'enums', '$state'];

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...