Angular Route JS does not open in page load

0

I have a template and two routes, none open on page load (or F5), but if I make a $ state.go ('RotateName '), it loads properly.

// routes.js

angular.module('app').config([
'$stateProvider', '$urlRouterProvider', '$locationProvider',
function ($stateProvider, $urlRouterProvider, $locationProvider) {
    console.log('Register routes...');

    $urlRouterProvider.otherwise("/demo-register");

    $stateProvider.state('quickRegister', {
        url: '/quick-register',
        templateUrl: 'path/para/quick-register.html',
        controller: 'QuickRegisterController'
    }).state('demoRegister', {
        url: "/demo-register",
        templateUrl: 'path/para/demo-register.html',
        controller: 'DemoRegisterController'
    });
}]);
<!-- template.html -->
<div class="main" ng-controller="CleanController">
    <div id="header">
        <div class="container">
            <img ng-src="{{headerSrc}}">
            <hr>
        </div>
    </div>
    <div id="content" ui-view></div>
</div>
angular.module('app').controller('CleanController', [
    '$scope', '$state',
    function ($scope, $state) {
        console.log('$state.current', $state.current)
        // output: $state.current {name: "", url: "^", views: null, abstract: true}
    }
]);

Note that in CleanController I gave a console.log from the current state , and it returned a "blank" state, but at no time did I set this state .

Does anyone have any ideas how to fix the problem?

    
asked by anonymous 09.05.2018 / 21:11

1 answer

0

I could solve by creating a state abstract :

$stateProvider.state('clean', {
    abstract: true,
    templateUrl: 'path/para/template.html'
}).state('clean.quickRegister', {
    url: '/quick-register',
    templateUrl: 'path/para/quick-register.html',
    controller: 'QuickRegisterController'
}).state('clean.demoRegister', {
    url: "/demo-register",
    templateUrl: 'path/para/demo-register.html',
    controller: 'DemoRegisterController'
})
    
10.05.2018 / 00:06