$ state.go('state.name')没有正确改变状态

Xan*_*iff 2 angularjs angular-ui-router

我试图以编程方式在状态之间移动(使用ui.router)而无需用户点击任何内容.http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$ state 的文档似乎表明我可以用$ state.go('state.名称"),除了我无法使这项工作.

我创造了一个用来证明我的问题的傻瓜.国家最好能够切换它的运行时显示"成功",而不是"失败".如果你看一下控制台,它会说,它无法读取的未定义的属性"走".我怎么能以编程方式改变状态呢?

谢谢!

http://plnkr.co/edit/MSLbKaKzmuXPud7ZcKqs

编辑:更清楚地指明我正在使用ui.router

Moh*_*and 12

2件事:

  1. 你忘了注入$state你的app.run()
  2. $stateChangeSuccess改用

    .run(['$rootScope','$state', function($rootScope, $state) { $rootScope.$on('$stateChangeSuccess', function(event, next) { $state.go('root.other'); })}]);

工作插件.