jonhobbs
jonhobbs

Reputation: 27962

Angular-UI router, not refresh if coming from /modal routes

Is it possible to configure something globally so that every time a new route is entered it checks to see if the previous route began with /modal and if it did then don't refresh the controller, just remove the top modal from the stack?

I think I could probably achieve this with reloadOnSearch and using search parameters but then I'd have to set every route on the whole site to set reloadOnSearch because any route on the site could launch a modal so this is not desirable.

Any help would really be appreciated.

Upvotes: 0

Views: 154

Answers (2)

Praveen Prasad
Praveen Prasad

Reputation: 1993

Have you tried this?

$rootScope.$on('$stateChangeStart', 
function(event, toState, toParams, fromState, fromParams){ 
     //codes
})

Upvotes: 1

Jahongir Rahmonov
Jahongir Rahmonov

Reputation: 13733

In simple angular route you could do this:

yourApp.run(function($rootScope, $location){
  $rootScope.$on('$routeChangeStart', function(evt, next, current) {
    // next: The next URL to which we are attempting to navigate
    // current: The URL that we are on before the route change

    if (current == 'modal1'){
        evt.preventDefault();
    }
  });
})

In order to adjust this to angular ui, just change $routeChangeStart to the relevant one($stateChangeStart, I think).

Upvotes: 0

Related Questions