【问题标题】:Unknown provider: serviceProvider -> service -> myDirective未知提供者:serviceProvider -> service -> myDirective
【发布时间】:2018-09-29 12:50:20
【问题描述】:

最近对我正在开发的软件的更改给我留下了以下错误:

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

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

我已经看过的网站:

查看所有这些并正确测试(重新创建此错误)后,您需要了解以下内容:

  • 有问题的项目是一个调用模式的组件,以便您 可以搜索买家/业务合作伙伴
  • 在新实现上调用模态,但不在同一代码的任何旧实现上。
  • 这是指令开头的样子:

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

请帮我找出问题

【问题讨论】:

  • 你在index.html中添加了.js文件吗?
  • 哪个 .js 文件?指令还是服务?
  • 服务。角度无法找到注入指令的服务文件。此外,您提供的代码 sn-p 都是 directives 而不是 service
  • 抱歉混淆了我实际上为服务使用了错误的代码
  • 但是 .js 被添加到 index.html 中

标签: angularjs web service angularjs-directive


【解决方案1】:

您还没有将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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-27
    • 2016-11-29
    • 2018-09-28
    • 2014-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多