简体   繁体   English

为什么我的Angular状态没有被加载?

[英]Why my Angular state is not being loaded?

At the start of my app, I have : 在我的应用程序启动时,我有:

$urlRouterProvider.otherwise('/loading');

which brings control to my loadCtrl . 这将控制权交给了我的loadCtrl Here I have: 我在这里:

Service.getRoleDetails(config.USER_DETAILS_URL).then(useRoleDetails, handleApiError);

        function useRoleDetails(response) {
            if (response.id === 1) {
                $state.go('home');
            }
            else
                $state.go('master');
        }

        function handleApiError(error) {
            Overlay.applyOverlay(false);
        }

This servcie call and callback function works fine. 此servcie调用和回调函数可以正常工作。 The if - conditions gets fulfilled but somehow the state do not change to home . 如果条件得到满足,但是状态不会改变为home My screen is stuck at the initial page only. 我的屏幕仅停留在初始页面。 (which is the template for `/loading'.) (这是`/ loading'的模板。)

I have never faced such issue with $state , Am I doing something wrong?? 我从未遇到过$state这样的问题,我做错了吗? Though I have no console errors 虽然我没有控制台错误

Any suggestion?? 有什么建议吗?

My config: 我的配置:

$stateProvider.state('preload', {
            url: '/loading',
            views: {
                "main": {
                    controller: 'landingPageCtrl as lc',
                    templateUrl: 'PP/htmls/landing.tpl.html'
                }
            },
            data: {
                pageTitle: 'PricingPlan'
            }
        })
        .state('home', {
            url: '/pricingplan',
            views: {
                "main": {
                    controller: 'PPCtrl as pp',
                    templateUrl: 'PP/htmls/pricing-position.tpl.html'
                }
            },
            data: {
                pageTitle: 'Pricing Plan'
            }
        })
        .state('master', {
            url: '/master',
            views: {
                "main": {
                    controller: 'masterDataCtrl as mdc',
                    templateUrl: 'PP/htmls/MasterData/masterData.tpl.html'
                }
            },
            data: {
                pageTitle: 'Master Data'
            }
        })
        .state('logout',{
            url: '/loggedOut',
            views: {
                "main": {
                    controller: 'logOutCtrl as lc',
                    templateUrl: 'PP/htmls/logout.tpl.html'
                }
            },
            data: {
                pageTitle: 'Session Expired'
            }
        });


    }

I dug deeper and found that everything was OK with Angular and my above implementation (in Question). 我更深入地研究,发现Angular和上面的实现(问题中)都可以。 However, I had an existing logic in my $stateChangeStart event listener. 但是,我在$stateChangeStart事件侦听器中已有一个逻辑。 The state change was getting restricted there. 状态更改在那里受到限制。

Anyone facing any issue of such kind should have one look in $stateChangeStart listener. 面对此类问题的任何人都应该在$stateChangeStart侦听器中查看一下。

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

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