如何在指令范围内为$ modal设置“内联"控制器? [英] How to set 'inline' controller for $modal in a directive's scope?
本文介绍了如何在指令范围内为$ modal设置“内联"控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在指令内打开Bootstrap UI $ modal.它可以工作,但是当我想添加一个内联"控制器(请参见下面的代码中的注释行)时,出现"[$ injector:unpr]未知提供程序:nProvider<-n"错误.
I'm trying to open a Bootstrap UI $modal inside a directive. It works, but when I want to add an 'inline' controller (see commented lines in the code below), I get a "[$injector:unpr] Unknown provider: nProvider <- n" error.
谁能告诉我为什么?
angular.module('myApp.directives').directive('eModalForm', ['$modal', function ($modal) {
return {
restrict: 'A',
link: function ($scope, $element, $attrs) {
$scope.openModal = function () {
console.log('//==//');
var modalInstance = $modal.open({
templateUrl: '/App/Templates/modal.html',
// commented these lines to prevent error:
//controller: function ($scope, $modalInstance) {
// $scope.$modalInstance = $modalInstance;
//},
size: 'lg'
});
};
}
};
}]);
我这样调用此函数:
<div ng-repeat="item in list" ng-click="openModal(item)" e-modal-form>
推荐答案
缩小过程中丢失了控制器依赖性,只需使用扩展语法即可:
The controller dependencies are lost during minification, just use the extended syntax:
controller: ['$scope', '$modalInstance', function ($scope, $modalInstance) {
...
}],
...
这篇关于如何在指令范围内为$ modal设置“内联"控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文