在angularjs中使用$ uibModal的奇怪行为

时间:2016-06-26 21:16:33

标签: angularjs twitter-bootstrap

我正在开发AngularJs应用程序,我需要在出错时显示ajax请求的弹出窗口。我正在使用bootstrap Modal弹出窗口,但我面临着非常奇怪的问题。

这是我的控制器代码

var upComingGroupEventsController = function ($scope, $window, $routeParams, $uibModal, $location, $filter, DataService, SharedProperties, ngDialog) {
    var groupId = $routeParams.groupid;

    var onUpcomingGroupError = function (data) {
        $scope.modalOptions.headerText = "Error";
        $scope.modalOptions.bodyText = data.statusText;


        var upcomingGroupErrorModel = $uibModal.open({
            templateUrl: window.serverURL + 'app/ErrorMessages/PopUpErrorMessage.html',
            controller: 'upComingGroupEventsController'
        });

        $scope.cancelForm = function () {
            upcomingGroupErrorModel.close();
        };
    };

    $scope.upComingGroupData = [];

    $scope.load = function () {

        $scope.modalOptions = {
            headerText: "",
            bodyText: ""
        }

        var onUpcomingEventsComplete = function (data) {
            $scope.upComingGroupData = data;
        };

        DataService.getListOfUpcomingEventsByGroupId(groupId)
            .then(onUpcomingEventsComplete, onUpcomingGroupError);
    };

    $scope.load();
}

angularFormsApp.controller("upComingGroupEventsController", ["$scope", "$window", "$routeParams", "$uibModal", "$location", "$filter", "DataService", "SharedProperties", "ngDialog", upComingGroupEventsController]);

和下面的DataService调用方法

[HttpGet]
        [Route("m/api/Group/{groupId}/UpcomingEvents")]
        public IHttpActionResult ListOfUpcomingEventsByGroupId(string groupId)
        {
            try
            {
                int a = 1, b = 1, c = 0;
                a = b/c;
                var listOfUpcomingEvents = GroupExecutor.GetListOfUpcomingEventsByGroupId(groupId);
                return Ok(listOfUpcomingEvents);
            }
            catch (Exception ex)
            {
                LogClass.Logger.Error(ex.Message, ex);
                return InternalServerError();
            }
        }

在这里,我强行抛出异常,我可以弹出错误。

但是它在返回错误之后......

  1. 弹出窗口正在打开但空白

  2. 它一次又一次地重复..我的意思是在显示弹出窗口后再次调用该数据服务并再次弹出,以便为什么它会在出错时循环?

0 个答案:

没有答案