简体   繁体   English

检查ui状态是否具有转发ui状态

[英]Check whether ui-state has forward ui-state

I think it is a simple question but could not find on google. 我认为这是一个简单的问题,但在Google上找不到。 I am using angular 1.5 and ui-router 1.5. 我正在使用angular 1.5和ui-router 1.5。 How do I check if current ui-view state had next ui-state? 如何检查当前ui视图状态是否具有下一个ui状态? (This is required because I want to check whether current ui-view is loaded when back button is pressed or through direct link) (这是必需的,因为我想检查是否在按下后退按钮或通过直接链接时加载了当前的用户界面)

Case 1
--------
view1 -> view2 -> view3 // now I have pressed back button 
view1 -> view2 ? // Here view2 actually had next state that was view3

Case 2
--------
view1 -> view4 -> view2 //Here view2 do not have next ui-state 

I have tried using $ionicHistory.forwardView() but it always return null. 我尝试使用$ionicHistory.forwardView()但它始终返回null。 Not sure why? 不知道为什么吗? Any help is greatly appreciated. 任何帮助是极大的赞赏。

After googling for 4 hours I have come up with some custom solution. 谷歌搜索4小时后,我想出了一些自定义解决方案。 would like to share. 想分享。 Proper error handling has to be done yet. 还必须进行正确的错误处理。

// just listen to statechange success event 
app.run(['$rootScope', function($rootScope){
   $rootScope.$on('$stateChangeSuccess', 
      function(event, toState, toParams, fromState) {
        // if fromState.name is empty, its refresh || first landing
        var history = $window.localStorage.getItem('history');
        var back = false;
        if (history !== null) {
            history = JSON.parse(history);
            if (toState.name === history.from && fromState.name === history.to) {
                back = true;
            }
        }
        $window.localStorage.setItem('history', JSON.stringify({
            to: toState.name,
            from: fromState.name,
            isBack: back
       }));
   });
});

Note I have used persistent storage technique. 注意我已经使用了持久存储技术。 One must handle refresh condition also. 一个人也必须处理刷新条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM