AngularJS ui引导模式实例问题
我有AngularJS应用程序(版本1.4.7)和最新版本的ui.bootstrap。当我尝试注入$uibModalInstance时出现问题,该实例抛出错误AngularJS ui引导模式实例问题,angularjs,angular-bootstrap,Angularjs,Angular Bootstrap,我有AngularJS应用程序(版本1.4.7)和最新版本的ui.bootstrap。当我尝试注入$uibModalInstance时出现问题,该实例抛出错误未知提供程序:$uibModalInstanceProvider 以下是控制器代码: /** * @constructor * @param $uibModal */ function ClientsController($uibModal) { var _this = this; _this.$uibModal =
未知提供程序:$uibModalInstanceProvider
以下是控制器代码:
/**
* @constructor
* @param $uibModal
*/
function ClientsController($uibModal)
{
var _this = this;
_this.$uibModal = $uibModal;
}
/**
*
*/
ClientsController.prototype.create = function()
{
var instance = this.$uibModal.open(
{
animation: true,
templateUrl: 'modules/clients/views/modal/client.html',
controller: 'ClientModalInstController as ctrl',
size: 'lg'
}
);
};
这是模态控制器
ClientModalInstController.$inject = [
'$uibModalInstance'
];
/**
* @constructor
* @param $uibModalInstance
*/
function ClientModalInstController($uibModalInstance)
{
var _this = this;
_this.$uibModalInstance = $uibModalInstance;
}
知道是什么导致了这种行为吗?导致这种行为的原因如下:
$uibModal.open()
返回一个$modalInstance
,它需要将$uibModalInstance
依赖项注入到ClientModalInstController
控制器中。我看不到ClientModalInstController
的代码,但它需要将$uibModalInstance
注入其中,这与$uibModal
您可以在ui引导文档中模式示例的javascript选项卡中看到此示例:
向下滚动到文档的模式部分,查看Javascript选项卡中的代码,查找
ModalInstanceCtrl
及其注入的依赖项。@SilvioMarijic如果项目注入顺序不正确,则此操作将中断。确保所有东西都排好了
代码示例:
angular.module('App').controller('YourController', ['$scope', '$http', '$uibModal',
function ($scope, $http, $uibModal) {
//CODE HERE
}]);
假设您在构造函数(任意一行)中交换了$http和$uiModal,您将得到描述的错误 我已经注入了$uibModalInstance,这是它抛出错误的部分$uibModalInstance已经被注入,只有注入才会抛出错误。你在哪里注册
ClientModalInstController
作为控制器?该代码在$InjectBlock之上,我只是没有在这里显示它在这里似乎正常工作~。一定是你错过了什么。你的模块的依赖关系是什么?我已经看到了plnkr,我不知道我遗漏了什么。我已经将ui.bootstrap添加到modul。有线的事情是,我能够打开模态,但当我尝试注入模态实例时,它会将ngstrictdi
属性添加到元素中,并使用ngapp
。这可能有助于指出任何错误。