首页 > 解决方案 > Bootstrap 确认模态窗口服务

问题描述

大家好,我有服务可以打开带有问题和 2 个按钮的引导模式窗口(ui-bootstrap)。如果用户点击确定或没有按钮,我想要处理,而不是我想删除项目或只是关闭模式窗口。我想在用户可以删除任何项目的每个地方(在不同的控制器中)调用此服务。问题是如何修改这个服务来做到这一点?

模板 :

> <div class="modal-header">
>     <h4>Delete confirmation</h4> </div> <div class="modal-body">
>     <p>Item will be permanently deleted! Do you want to continue?</p> </div> <div class="modal-footer">
>     <button type="button" class="btn" 
>         data-ng-click="cancel()">No</button>
>     <button class="btn btn-danger" 
>         data-ng-click="ok();">Ok</button> </div>

服务 :

myApp.service('modalService', [
    '$modal', function ($modal) {
        var self = this;
        var modalInstance = null;

        self.open = function ($scope, path) {
            modalInstance = $modal.open({
                templateUrl: path,
                scope: $scope
            });
        };

        self.close = function () {
            modalInstance.dismiss('close');
        };

        return self;
    }
]);

呼叫服务:

> $scope.deleteTest = function () {
>     modalService.open($scope,'js/app/templates/confirmation-modal.html');
// I want to continue to do my delete if Ok button on modal was hit ....
> };

标签: angularjsangular-ui-bootstrap

解决方案


推荐阅读