【问题标题】:How to Reload the page when I close pop up container?关闭弹出容器时如何重新加载页面?
【发布时间】:2018-03-23 13:01:20
【问题描述】:

我正在使用 $mdDialog 来显示弹出警报。每当我关闭弹出容器时,我都想刷新页面。

 $scope.updateCustomer = function(){
   HomeService.updateCustomer($scope.update)
    .then (function success(response){ 
        $mdDialog.show(
            $mdDialog.alert()
              .parent(angular.element(document.querySelector('#popupContainer')))
              .clickOutsideToClose(true)
              .textContent("Username has been changed successfully!")
              .ariaLabel('')
              .ok('Ok')
          );
    },
    function error(response){
        $mdDialog.show(
            $mdDialog.alert()
              .parent(angular.element(document.querySelector('#popupContainer')))
              .clickOutsideToClose(true)
              .textContent("Something is wrong!")
              .ariaLabel('')
              .ok('Ok')
          );
  });
} 

关闭弹窗时如何刷新页面?

【问题讨论】:

    标签: angularjs angularjs-material


    【解决方案1】:

    这是我的问题的有效答案...

     $scope.updateCustomer = function(){
       HomeService.updateCustomer($scope.update)
        .then (function success(response){ 
            $mdDialog.show(
                $mdDialog.alert()
                  .parent(angular.element(document.querySelector('#popupContainer')))
                  .clickOutsideToClose(true)
                  .textContent("Username has been changed successfully!")
                  .ariaLabel('')
                  .ok('Ok')
                  .onRemoving(window.location.reload())
              );
    
        },
        function error(response){
            $mdDialog.show(
                $mdDialog.alert()
                  .parent(angular.element(document.querySelector('#popupContainer')))
                  .clickOutsideToClose(true)
                  .textContent("Something is wrong!")
                  .ariaLabel('')
                  .ok('Ok')
    
              );              
      });
    } 
    

    【讨论】:

      【解决方案2】:

      页面重新加载并不完全是 angularjs 模式,但您可以使用:

      $mdDialog
        .show({
          ...
          onRemoving: function() {
            window.location.reload();
          }
        });
      

      参考:$mdDialog Service

      【讨论】:

      • 我建议为window 使用AngularJS 包装器:$window
      猜你喜欢
      • 1970-01-01
      • 2013-09-15
      • 1970-01-01
      • 2012-07-09
      • 2011-08-21
      • 1970-01-01
      • 1970-01-01
      • 2014-07-01
      • 1970-01-01
      相关资源
      最近更新 更多