Prevent a stateChange with angular ui router without using $rootScope

后端 未结 3 557
独厮守ぢ
独厮守ぢ 2021-01-31 08:55

My user can leave a state but before I want to show a modal dialog \"Do you want to save?\"

ONLY if the user data is dirty that means changed.

What I do NOT wan

3条回答
  •  攒了一身酷
    2021-01-31 09:14

    (1) According to the docs under State Change Events

     $rootScope.$on('$stateChangeStart', 
          function(event, toState, toParams, fromState, fromParams){ 
              event.preventDefault(); 
              // transitionTo() promise will be rejected with 
              // a 'transition prevented' error
     })
    

    You could change $rootScope to $scope wherever appropriate and works.

    Under Attach Custom Data to State Objects, you can pass on custom data.

    (2) I'm not sure what you're asking but factories/services/providers would really help.

提交回复
热议问题