未知提供程序尝试在Angular控制器上注入依赖项时出错

Unknown provider Error when trying to inject dependency on Angular controller

本文关键字:注入 依赖 出错 控制器 Angular 程序 未知      更新时间:2023-09-26

我正试图以以下方式在我的userMenuController中注入"modal"指令:

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

这是modals.js:

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

在app.js上,应用程序的定义如下:

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

我错过了什么?

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

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

在index.html文件