AngularJS [removed] in one controller is being triggered on another controller

后端 未结 4 1599
闹比i
闹比i 2021-02-01 18:16

Here is my problem, I have two views (View1 and View2) and a controller for each view (Ctrl1 and Ctrl2). In View1 I\'m trying to warn the user before he leaves the page accident

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-01 19:15

    For those of you using angular-ui-router you would use is $stateChangeStart instead of $locationChangeStart, e.g.

    $scope.$on('$stateChangeStart', function (event){
      if (forbit){
        event.preventDefault()
      }
      else{  
        return
      }
    })
    

提交回复
热议问题