如何在指令范围内为 $modal 设置 'inline' 控制器?
How to set 'inline' controller for $modal in a directive's scope?
我正在尝试在指令中打开 Bootstrap UI $modal。它有效,但是当我想添加一个 'inline' 控制器时(请参阅下面代码中的注释行),我收到“[$injector:unpr] Unknown provider: nProvider <- n”错误。
谁能告诉我为什么?
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>
控制器依赖关系在缩小过程中丢失,只需使用扩展语法:
controller: ['$scope', '$modalInstance', function ($scope, $modalInstance) {
...
}],
...
我正在尝试在指令中打开 Bootstrap UI $modal。它有效,但是当我想添加一个 'inline' 控制器时(请参阅下面代码中的注释行),我收到“[$injector:unpr] Unknown provider: nProvider <- n”错误。
谁能告诉我为什么?
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>
控制器依赖关系在缩小过程中丢失,只需使用扩展语法:
controller: ['$scope', '$modalInstance', function ($scope, $modalInstance) {
...
}],
...