Rustery
Rustery

Reputation: 125

How to show angular ui modal when location change?

How to show angular ui modal when location change?

Now I have these controllers:

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 );
  };
};

How to open modal, when i go to some location? Thanx.

Upvotes: 0

Views: 511

Answers (1)

alfrescian
alfrescian

Reputation: 4079

If you're not coming to the same route, then you can watch $routeChangeSuccess

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

If you don't use routes at all, then there is afaik also an event $locationChangeSuccess that you can listen to in the same way:

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

Upvotes: 1

Related Questions