从不同的文件关闭bootstrap uibmodal

时间:2017-09-20 12:15:29

标签: html angularjs bootstrap-modal

每次打开页面时,我都会打开一个uibModal,如:

genres.js

        app.controller('genresController', ['$scope', '$http', '$uibModal', 'blockUI', 'notifyService', 'lib',
function ($scope, $http, $uibModal,blockUI, notifyService, lib) {
        $scope.genres = [];
        var init = function () {
            //Initial code
            loadGenres();
        };


        var loadGenres = function () {

            /*... some non-important codes... */

            openFavoriteGenreDialog();

            /*... some non-important codes... */

            }, lib.handleError);
        };

        var openFavoriteGenreDialog = function () {
            var modalInstance = $uibModal.open({
                templateUrl: '/Dialog/FavoriteGenre',
                controller: 'favoriteGenreDialogController'
            });
            modalInstance.result.then(function (msg) {


            }, function (msg) {
                //dismiss callback
            });
        };

        init();
}]);

并且模态控制器在另一个文件中,该模态的html有一个取消按钮。

FavoriteGenre.cshtml

        <button class="btn btn-default" type="button" ng-click="cancel()">Cancel</button>

该取消按钮正在另一个控制器中处理,该控制器具有到目前为止的功能

favGenrer.js

    $scope.cancel = function () {
        var modalInstance = $uibModal.open({
            templateUrl: '/Dialog/FavoriteGenre',
            controller: 'favoriteGenreDialogController'
        });
        modalInstance.close();
    };

由于这种结构,每次按下取消按钮时我都会打开和关闭模态。无论如何,即使cancel()函数在另一个文件中的另一个控制器中,当我按下关闭按钮时我可以关闭模​​态?我试图在genres.js上放置cancel()函数,但由于genresControllers的其他方法,我无法使html调用genresController而不会产生大量的错误。

ANSWER

找出来!问题是在我正在做的FavoriteGenre.cshtml中

    <div ng-controller="favoriteGenreDialogController" block-ui="genresContentDiv">

我只需要让它像:

    <div  block-ui="genresContentDiv">

它使用

工作
    $scope.cancel = function () {
        $uibModalInstance.dismiss('cancel');
    };

1 个答案:

答案 0 :(得分:0)

试试这个。

$scope.cancel = function () {
        $uibModalInstance.dismiss('cancel');
    };