angularjsangularjs-injector

Error: [$injector:unpr] Unknown provider: nxProvider <- nx <- adminController


I'm working on AngularJS (v1.6) app where I get following error. I tried to follow as per the suggested link (https://code.angularjs.org/1.6.5/docs/error/$injector/unpr?p0=nxProvider%20%3C-%20nx%20%3C-%20adminController) but it didn't worked.

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">"

If I remove nx injector, then it gives error related to http provider. Error: [$injector:unpr] Unknown provider: httpProvider <- http <- adminService

Here's my admin.controller.js code:

(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 **/
        }
})();

and admin.service.js as follows:

(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
    }
};
})();

Thanks in advance!


Solution

  • you are missing nx token injection in here: adminService.$inject = ['http', 'enums', '$state'];

    Change to: adminService.$inject = ['nx', 'http', 'enums', '$state'];