我正在使用 Angular Bootstrap ui 模态框,它说要为新控制器提供一个新的 $modalInstance。我想使用与初始化模态框相同的控制器。我搜索但没有成功。我找到了此链接,但没有成功 -
如何在 Angular UI Bootstrap 中对模态和非模态形式使用相同的控制器? https://stackoverflow.com/questions/23780950/how-to-use-the-same-controller-for-modal-and-non-modal-form-in-angular-ui-bootst
Angular-ui 引导模式无需创建新控制器 https://stackoverflow.com/questions/23756105/angular-ui-bootstrap-modal-without-creating-new-controller
app.controller('UserCtrl',['$scope','$filter','ngTableParams','$modal',function($scope, $filter, ngTableParams,$modal) {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl', //Instead of this i want to use the same controller 'UserCtrl'
size: size,
resolve: {
items: function () {
return $scope.items;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
};
} ]);
这样我就可以在同一个控制器上调用保存函数,该函数在模态框的保存单击时调用