modal in angular-ui示例在ModalInstanceCtrl
控制器中使用ModalDemoCtrl
实现,如下所示:
var ModalDemoCtrl = function ($scope, $modal, $log) {
$scope.open = function () {
var modalInstance = $modal.open({
...
controller: ModalInstanceCtrl,
...
});
...
};
};
var ModalInstanceCtrl = function ($scope, $modalInstance, items) {
...
$scope.ok = function () {
$modalInstance.close($scope.selected.item);
};
};
尝试使用角度控制器时尝试这种方法:
app.controller('ModalInstanceCtrl', ['$scope', '$modal', '$log',
function ($scope, $modalInstance, items) {
...
$scope.ok = function () {
$modalInstance.close($scope.selected.item);
};
}]);
app.controller('ModalDemoCtrl', ['$scope', '$modal', '$log', 'ModalInstanceCtrl',
function ($scope, $modal, $log, ModalInstanceCtrl) {
$scope.open = function () {
var modalInstance = $modal.open({
...
controller: ModalInstanceCtrl,
...
});
...
};
}]);
我收到以下错误:
Error: Unknown provider: ModalInstanceCtrlProvider <- ModalInstanceCtrl
是否可以以角度嵌入这样的控制器?
答案 0 :(得分:4)
您无需将ModelInstanceCtrl
注入ModalDemoCtrl
。控制器定义应为
app.controller('ModalDemoCtrl', ['$scope', '$modal', '$log',
function ($scope, $modal, $log) {
没有这个也应该有效。如果没有尝试
var modalInstance = $modal.open({
...
controller: 'ModalInstanceCtrl',
...
});