angularjs ui-router父状态解决每个子状态更改

时间:2017-07-31 09:47:00

标签: angularjs angular-ui-router

我有一个永远不会导航到的父状态:

function wizard($stateProvider) {

    $stateProvider
        .state('home.category', configureCategoryRoute());

    function configureCategoryRoute() {
        return {
            url: ':categoryName?g',
            views: {
                '@': {
                    templateUrl: 'app/wizard/wizard.html',
                    controller: 'WizardController',
                    controllerAs: 'controller'
                },
                'menu@': {
                    templateUrl: 'app/menu/menu.html',
                    controller: 'MenuController',
                    controllerAs: 'controller'
                }
            },
            resolve: {
                options: getOptions,
                category: ['$stateParams', 'categoryService', function ($stateParams, categoryService) {
                    console.log('once');
                    return categoryService.get($stateParams.categoryName);
                }],
                criteria: ['category', 'criteriaService', function (category, criteriaService) {
                    return criteriaService.list(category.id, 'attributes');
                }],
                groups: ['category', 'wizardService', function (category, wizardService) {
                    return wizardService.listGroups(category.id);
                }],
                products: ['category', 'wizardService', function (category, wizardService) {
                    return wizardService.listProducts(category.id);
                }],
                questions: ['category', 'groups', 'criteria', 'questionProvider', function (category, groups, criteria, questionProvider) {
                    return questionProvider.list(category, groups, criteria, 'answers.formulas');
                }],
                settings: ['settingService', function (settingService) {
                    return settingService.list();
                }],
                decode: ['$stateParams', 'questions', 'encoder', 'questionProvider', function ($stateParams, questions, encoder, questionProvider) {
                    var simpleGroups = encoder.decode($stateParams.g);

                    return questionProvider.applyAnswers(questions, simpleGroups);
                }]
            }
        };
    };

    function getOptions($location) {
        return {
            matches: $location.search().matches === '1',
            showHeader: $location.search().showHeader === '1'
        };
    };
};

然后我有一组子状态:

function stepOne($stateProvider) {

    $stateProvider
        .state('home.category.one', configureOneRoute());

    function configureOneRoute() {
        return {
            url: '/one',
            views: {
                '': {
                    templateUrl: 'app/one/one.html',
                    controller: 'StepOneController',
                    controllerAs: 'controller'
                }
            },
            resolve: {
                score: ['wizardService', 'groups', 'products', 'decode', function (wizardService, groups, products) {
                    return wizardService.score(groups, products);
                }]
            },
            data: {
                pageTitle: 'Step one'
            }
        };
    };
};

function stepTwo($stateProvider) {

    $stateProvider
        .state('home.category.two', configureTwoRoute());

    function configureTwoRoute() {
        return {
            url: '/two',
            views: {
                '': {
                    templateUrl: 'app/two/two.html',
                    controller: 'StepTwoController',
                    controllerAs: 'controller'
                }
            },
            resolve: {
                score: ['wizardService', 'groups', 'products', 'decode', function (wizardService, groups, products) {
                    return wizardService.score(groups, products);
                }]
            },
            data: {
                requireLogin: true,
                pageTitle: 'Step two'
            }
        };
    };
};

所以第一步和第二步是巫师的孩子。向导无法导航到(它将始终首先转到步骤1)。这里奇怪的问题是,每当我们从第1步移到第2步时, console.log('曾经')就会触发,但我认为不应该这样做。我确信父状态解析只有在你改变他们的状态时才会被解雇(比如去一个完全不同的状态而不是巫师的孩子)。

我想这里的问题是:我错了吗?在任何状态变化之后(不管他们是否是孩子),或者我做错了什么,父州解决了吗? 请帮忙!

0 个答案:

没有答案