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

前端 未结 2 1936
渐次进展
渐次进展 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);
    

提交回复
热议问题