Error: [$injector:unpr] Unknown provider: nxProvider <- nx <- adminController
Error: [$injector:unpr] Unknown provider: nxProvider <- nx <- adminController
我在开发 AngularJS (v1.6) 应用程序时出现以下错误。我尝试按照建议的 link (https://code.angularjs.org/1.6.5/docs/error/$injector/unpr?p0=nxProvider%20%3C-%20nx%20%3C-%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
}
};
})();
提前致谢!
您在此处缺少 nx
令牌注入:
adminService.$inject = ['http', 'enums', '$state'];
更改为:
adminService.$inject = ['nx', 'http', 'enums', '$state'];
我在开发 AngularJS (v1.6) 应用程序时出现以下错误。我尝试按照建议的 link (https://code.angularjs.org/1.6.5/docs/error/$injector/unpr?p0=nxProvider%20%3C-%20nx%20%3C-%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
}
};
})();
提前致谢!
您在此处缺少 nx
令牌注入:
adminService.$inject = ['http', 'enums', '$state'];
更改为:
adminService.$inject = ['nx', 'http', 'enums', '$state'];