未知提供商:serviceProvider - >服务 - > myDirective

时间:2018-04-19 06:14:25

标签: angularjs web service angularjs-directive

我正在处理的软件最近的更改给我留下了以下错误:

  

"异常:错误:[$ injector:unpr]未知提供者:tableNavigationProvider< - tableNavigation< - ajSearchSelectDirective   http://errors.angularjs.org/1.4.7/ $注射器/ unpr P0 = tableNavigationProvider%20%3 C-%20tableNavigation%20%3 C-%20ajSearchSelectDirective"

现在我已经查看了多个堆栈溢出板,但它们都没有任何帮助。如何找到此错误的问题?

我已查看过的网站:

在查看所有这些并正确测试(重新创建此错误)之后,您需要了解这一点:

  • 有问题的项目是调用模态的组件,以便您 可以搜索买家/ businessPartner
  • 在新实现上调用模态但不在相同代码的任何旧实现上。
  • 这是指令的开头:

    (function () {
    var app = angular.module('ngiBusinessPartner');
    app.directive('ajSearchSelect', [
    '$timeout',
    'uiStateMachine',
    'formHelper',
    'spinnerService',
    'tableNavigation',
    ajSearchSelect]);
    
    function ajSearchSelect(
    $timeout,
    uiStateMachine,
    formHelper,
    spinnerService,
    tableNavigation) {
    //other code goes here
    }; })();
    
  • 这就是服务n问题的开头:

    (function () {
    'use strict';
    
    var app = angular.module('tableNavigation', []);
    
    app.service('tableNavigation', [
    '$document',
    '$timeout',
    tableNavigation
    ]);
    function tableNavigation($document, $timeout) {
    //other code goes here
    }; })();
    

请帮我找到问题

1 个答案:

答案 0 :(得分:0)

您尚未将tableNavigation注入ngiBusinessPartner模块。将您的代码更改为:

(function () {
var app = angular.module('ngiBusinessPartner',['tableNavigation']);
app.directive('ajSearchSelect', [
  '$timeout',
  'uiStateMachine',
  'formHelper',
  'spinnerService',
  'tableNavigation',
  ajSearchSelect]);

function ajSearchSelect(
$timeout,
uiStateMachine,
formHelper,
spinnerService,
tableNavigation) {
//other code goes here
}; })();

注意,您的var app = angular.module('ngiBusinessPartner');未注入tableNavigation模块。此外,尝试将服务或模块重命名为两个不同的名称。在您的代码中,两者都相同,即tableNavigation