[英]angular ui bootstrap - How to access modal scope without creating controller
The docs for the $modal
service say $modal
服务的文档说
The scope associated with modal's content is augmented with 2 methods:
与模式内容相关的范围通过两种方法扩大:
-
$close(result)
-
$close(result)
-
$dismiss(reason)
-
$dismiss(reason)
Those methods make it easy to close a modal window without a need to create a dedicated controller.
这些方法可以轻松关闭模态窗口,而无需创建专用控制器。
I'm wondering how to access this scope without creating a dedicated controller. 我想知道如何在不创建专用控制器的情况下访问该范围。
Try this: 尝试这个:
$scope.openModal=function(){
$scope.modalInstance=$modal.open({
templateUrl: 'xyz.html',
scope:$scope
});
}
$scope.close=function(){
$scope.modalInstance.dismiss();
};
now you can use ng-click="close()"
in your temnplate file. 现在您可以在模板文件中使用
ng-click="close()"
。
ı used this code. 我使用了这段代码。
module.service('ModalService', function ($modal) {
var modalOptions = {
backdrop: true,
keyboard: true,
modalFade: true,
templateUrl: null
};
this.show = function (customModalDefaults) {
var tempModalOptions = {};
angular.extend(tempModalOptions, modalOptions, customModalDefaults);
if (!tempModalOptions.controller) {
tempModalOptions.controller = function ($scope, $modalInstance) {
$scope.modalOptions.ok = function (result) {
$modalInstance.close(result);
};
$scope.modalOptions.close = function (result) {
$modalInstance.dismiss('cancel');
};
};
}
return $modal.open(tempModalOptions).result;
};
});
call: 呼叫:
var modalOptions = {
backdrop: true,
modal: true,
size: scope.options.size || 'lg',
templateUrl: '/Apps/inekle/views/common/include_modal.html?v=1',
controller: [
"$scope", "$modalInstance", function ($scope, $modalInstance) {
$scope.model = {
template: scope.options.template,
title: scope.options.title
};
$scope.close = function () {
$modalInstance.dismiss('close');
};
}
]
};
ModalService.show(this.options).then(function (model) {},function (error) { });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.