如何在位置更改时显示角度 UI 模式

How to show angular ui modal when location change?

本文关键字:显示 UI 模式 位置      更新时间:2023-09-26

位置更改时如何显示角度UI模式?

现在我有这些控制器:

var MainModalCtrl = function ($scope, $modal, $log) {
  $scope.open = function () {
    var modalInstance = $modal.open({
      templateUrl: 'mainMenuContent.html',
      controller: MainModalInstanceCtrl
    });
  };
};
var MainModalInstanceCtrl = function ($scope, $modalInstance) {
  $scope.close = function () {
    $modalInstance.dismiss('close');
  };
  $scope.content = 'Menu';
  $scope.showContent = function( index ) {
    $scope.content = ( index );
  };
};

当我去某个地方时,如何打开模态?谢谢。

如果你不在同一条路线上,那么你可以观看$routeChangeSuccess

 $scope.$on('$routeChangeSuccess', function () {
    $scope.open();
 }

如果您根本不使用路由,那么还有一个事件$locationChangeSuccess,您可以以相同的方式收听:

 $scope.$on('$locationChangeSuccess ', function () {
    $scope.open();
 }