User Cybermerlin User Cybermerlin - 2 months ago 22
AngularJS Question

how to create composite route in $stateProvider

If I go to /settings/wizard/hv then I see only Settings Page. what am I doing wrong?
I have Page: "Settings" url: '/settings'
on page button.handler > go to url: '/settings/wizard'

I have this code:

$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'
});


on Page '/settings/wizard/hv' I have some subPages and Views

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

Answer

First of all, try to add ui-view to your settings state template:

$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')
            }
        })

Child states requires a spot to render into.

Comments