【问题标题】:Closing bootstrap uibmodal from a different file从不同的文件关闭引导程序 uibmodal
【发布时间】:2017-09-21 01:45:59
【问题描述】:

每次打开页面时,我都会打开一个 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 上,但由于genresControllers 的其他方法,我无法让html 调用genresController 而不会出现很多错误。

回答

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

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

我只需要让它变成这样:

    <div  block-ui="genresContentDiv">

它使用

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

【问题讨论】:

  • 据我了解,您正在尝试执行不同控制器中的功能。我说得对吗..

标签: html angularjs bootstrap-modal


【解决方案1】:

试试这个。

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

【讨论】:

  • 如果我只这样做,我会得到“$uibModalInstance 未定义”错误。如果我注入它,模态不会关闭并且也会停止正常工作。
猜你喜欢
  • 2016-09-28
  • 2021-09-14
  • 2021-06-27
  • 1970-01-01
  • 2018-07-03
  • 1970-01-01
  • 1970-01-01
  • 2016-01-08
  • 1970-01-01
相关资源
最近更新 更多