【问题标题】:$stateChangeSuccess getting fired after controller is instantiated$stateChangeSuccess 在控制器被实例化后被触发
【发布时间】:2015-03-10 16:05:21
【问题描述】:

路线配置:

        $stateProvider.state('root', {
            url: "/",
            template: '<div ui-view></div>'
          })
      .state('root.child',{
         url: '/child',
         templateUrl: 'some.html'
         controller: function(){
             console.log('child')
         }
      });

StateChangeStart 监听器:

        $scope.$on('$stateChangeStart', function (event, state, params, fromState, fromParams) {
         console.log('state change start');
            }
        });

当我导航到状态“root.child”时,首先在控制台上打印“状态更改开始”,然后打印“孩子”。 但是当我在子状态下刷新页面或直接点击url'/child'时,首先打印'child'然后打印'state change start'。请帮忙。

【问题讨论】:

    标签: angularjs angular-ui-router


    【解决方案1】:

    您需要先致电event.preventDefault();

    为了您的利益,如果您想在$stateChangeStart 中运行$state 的地方做某事,它不会起作用。这是一个已知问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-07
      • 1970-01-01
      • 2013-07-06
      • 2013-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多