【问题标题】:Unknown provider Error when trying to inject dependency on Angular controller尝试注入对 Angular 控制器的依赖项时出现未知提供程序错误
【发布时间】:2015-11-04 13:43:24
【问题描述】:

我正在尝试通过以下方式在我的 userMenuController 中注入“modal”指令:

angular.module('mgApp.controllers').controller('userMenuController', ['$scope', 'modals', function($scope, modals) { ... }])

这里是 modals.js:

angular.module('mgApp.directives').directive('modals', function(){ ... })

在 app.js 上,app 是这样定义的:

var app = angular.module('mgApp',['templates', 'angularUtils.directives.dirPagination', 'mgApp.filters', 'mgApp.directives', 'mgApp.services', 'mgApp.controllers']);

但我不断收到此错误:

Error: [$injector:unpr] Unknown provider: modalsProvider <- modals <- userMenuController

我错过了什么?

【问题讨论】:

  • 为什么你不在同一个模块 mgApp 中的所有内容?我的意思是,你的指令和控制器?

标签: javascript angularjs angularjs-directive angular-controller


【解决方案1】:

快速思考:确保您已将所有 .js 文件包含为

<script src="*.js"></script> 

在 index.html 文件中

【讨论】:

  • 几乎每次都会发生在我身上:)
猜你喜欢
  • 1970-01-01
  • 2015-07-16
  • 1970-01-01
  • 2016-12-07
  • 1970-01-01
  • 1970-01-01
  • 2014-11-07
  • 1970-01-01
  • 2016-08-04
相关资源
最近更新 更多