2016-04-08 5 views
1

Hallo, ich habe ein Problem mit Elternstatus nicht aktiv, wenn Kind Anruf ist.Angular UI-Router Elternstatus nicht aktiv

Ich benutze UI-Router mit ui-sref-active Funktion.

Hier ist mein Router Code:

.state('customers', { 
    abstract: true, 
    parent: 'app', 
    url: '/customers', 
    templateUrl: 'app/customer/parent.html', 
}) 
.state('customers.list', { 
    parent: 'customers', 
    url: '', 
    controller: 'customerCtrl as customer', 
    templateUrl: 'app/customer/index.html' 
}) 

.state('customers.birthday', { 
    parent: 'customers', 
    url: '/birthday', 
    templateUrl: 'app/customer/birthday.html', 
}) 

Hier ist mein html:

<ul id="menu-sidebar"> 
    <li class="has_sub"> 
     <a ui-sref="customers.list" class="waves-effect" ui-sref-active="subdrop"> 
      <i class="fa fa-users"></i> <span> Customers</span> 
     </a> 
    </li> 
</ul> 

I ng-repeat bin mit, weil es viel Menü sind.

Das Problem ist, wenn ich rufe /customers die ui-sref-active funktioniert ordnungsgemäß. Aber wenn /customers/birthday aufrufen, ist ui-sref-active weg.

Hier unten Screenshot:

1 2

Ratschläge, wie sie arbeiten machen?

Vielen Dank im Voraus!

Antwort

0

ich es endlich lösen.

Bei meinem

app.run(['$rootScope', '$state', function($rootScope, $state) { 
    $rootScope.$on('$stateChangeStart', function(evt, to, params) { 
     if (to.redirectToChild) { 
     evt.preventDefault(); 
     $state.go(to.redirectToChild.state, params) 
     } 
    }); 
}]); 

app.config([ '$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) { 
    $urlRouterProvider.otherwise("/404"); 
    .state('customers', { 
     url: '/customers', 
     templateUrl: 'app/customer/parent.html', 
     redirectToChild: { 
       state: 'customers.list' 
      }, 
    }) 
    .state('customers.list', { 
     parent: 'customers', 
     url: '', 
     controller: 'customerCtrl as customer', 
     templateUrl: 'app/customer/index.html' 
    }) 

    .state('customers.birthday', { 
     parent: 'customers', 
     url: '/birthday', 
     templateUrl: 'app/customer/birthday.html', 
    }) 
}]); 
0

Könnte daran liegen, wie Ihre Nesting-Routen. Probieren Sie etwas wie folgt aus:

.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider) { 
$stateProvider 
.state('exampleState', { 
    url: '/example', 
    abstract: true, 
    templateUrl: 'templates/example/root-view.html', 
    controller: 'ParentCtrl' 
    }) 

    .state('exampleState.games', { 
    url: '/games', 
    views: { 
     'stats-games':{ 
     templateUrl: 'templates/example/firstpage.html', 
     controller: 'PageOneCtrl' 
     } 
    } 
    }) 
    .state('exampleState.sesaons', { 
    url: '/seasons', 
    views: { 
     'stats-games':{ 
     templateUrl: 'templates/example/secondpage.html', 
     controller: 'PageTwoCtrl' 
    } 
    }) 
}); 
+0

Arbeits Es ist nicht. Ich habe es versucht. Danke – ssuhat

0
.state('home', { 
     url: '/home', 
     abstract: true, 
     templateUrl: 'templates/home.html' 



    }) 
    .state('home.main', { 
     url: '', 
     templateUrl: 'templates/main.html' 



    }) 
    .state('home.owner', { 
     url: '/owner', 
     templateUrl: 'templates/owner.html' 

    }) 
+0

Sorry aber wird es wirklich ein Komma mit ui-sref-active auswirken? weil ich normalerweise Komma nach einem Objekt wie diesem setze. Und ich habe versucht, es zu entfernen, es ist kein Glück :) – ssuhat

+0

Bitte versuchen Sie diesen Weg und müssen nicht perent Attribut hinzufügen –

+0

ich entfernen mein Elternattribut, aber immer noch nicht funktioniert – ssuhat

Verwandte Themen