ui-router - $state.go() not working

前端 未结 2 1934
渐次进展
渐次进展 2021-01-13 07:28

Here is the app.js of my project:

(function () {
\'use strict\';

angular
    .module(\'app\', [\'ui.router\', \'ngCookies\', \'angular-inview\', \'ngMateria         


        
相关标签:
2条回答
  • 2021-01-13 08:03

    You need to execute the $state.go on main scope and not in a (angular) service or virtual scope created temporarily.

    You can also solve the problem by wrapping it in $timeout or setTimeout which will register it in the browser loop to be executed after the current method run etc even with 0 milliseconds will do it, like.

    $timeout(()=>{$state.go('xyz')},0)
    

    or

    setTimeout(()=>{$state.go('xyz')},0);
    
    0 讨论(0)
  • 2021-01-13 08:04

    Well, thanks to @Vanojx1, I found out adding e.preventDefault(); before the $state.go('login'); made it work. Still dont understand why though.

    0 讨论(0)
提交回复
热议问题