如何在$ stateProvider中创建复合路径

时间:2016-09-05 14:37:05

标签: angularjs angular-ui-router

如果我转到/ settings / wizard / hv,那么我只看到设置页面。我究竟做错了什么? 我有页面:“设置”网址:'/ settings' 在页面button.handler>转到网址:'/ settings / wizard'

我有这段代码:

    $stateProvider
            .state('settings', {
                url: '/settings',
                template: '<div>Settings panel with fields</div>',
                title: 'Конфигурация',
                controller: function(){
                    console.log('controller settings')
                }
            })

            .state('settings.wizard', {
                url: '/wizard',
                abstract: true,
                template: '<ui-view></ui-view>',
                title: 'Мастер настройки',
                /** @ngInject */
                controller: function($state, $scope, $controller){
                    console.log('controller Wizard');
                    if($scope.mode == 'vw'){
                        $state.go('settings.wizard.vw')
                    }else{
                        $state.transitionTo('settings.wizard.hv')
                    }
                }
            })

            .state('settings.wizard.hv', {
                url: '/hv',
                parent: 'settings.wizard',
                templateUrl: 'app/plugins/settings/wizard/tpl/wizard.html',
                title: 'Мастер настройки',
                /** @ngInject */
                controller: function ($controller, $scope) {
                    console.log('controller wizard/hv')
                    $scope.mode = 'hv';
                    var ctrl = $controller('Settings.Wizard');
                    ctrl.setMode('hv');
                },
                controllerAs: 'wizard'
            })
            .state('settings.wizard.vw', {
                url: '/vw',
                // parent: 'settings.wizard',
                templateUrl: 'app/plugins/settings/wizard/tpl/wizard.html',
                title: 'Мастер настройки',
                /** @ngInject */
                controller: function ($controller, $scope) {
                    console.log('controller wizard/vw')
                    $scope.mode = 'hv';
                    var ctrl = $controller('Settings.Wizard');
                    ctrl.setMode('vw');
                },
                controllerAs: 'wizard'
            });
页面上的

/ settings / wizard / hv'我有一些子页面和视图

<div>
  settings > wizard > hv
  <input />
  <ui-view></ui-view>
  <button onclick="$state.go('settings.wizard.hv.servers')" >go to servers</button>
</div>

1 个答案:

答案 0 :(得分:0)

首先,尝试将ui-view添加到您的settings州模板中:

$stateProvider
        .state('settings', {
            url: '/settings',
            template: '<section><div>Settings panel with fields</div><div ui-view></div></section>',
            title: 'Конфигурация',
            controller: function(){
                console.log('controller settings')
            }
        })

子状态需要一个点来渲染。