2016-04-08 23 views
1

こんにちは、私は親の状態で問題が子が呼び出されるときにアクティブになっています。角度のUIルータの親状態がアクティブでない

私はui-sref-active機能を持つui-routerを使用しています。

は、ここに私のルータのコードです:

.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', 
}) 

はここに私のhtmlです:メニューがたくさんありますので、私はNGリピートを使用してい

<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> 

/customersui-sref-activeが正しく動作していると問題が発生します。しかし、/customers/birthdayが呼び出されると、ui-sref-activeはなくなります。ここではスクリーンショット下の

1 2

それを操作できるようにする方法を任意のアドバイスはありますか?

ありがとうございます!

答えて

0

:このような何かを試してみてください。

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

あなたのネストルートのためかもしれません。私は最終的にそれを解決するため

.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

で、それは働いていません。私はあなたのやり方を試しました。ありがとう – 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

申し訳ありませんが、本当にカンマがui-sref-activeに影響しますか?私は通常そのようなオブジェクトの後にカンマを置くからです。そして、私はそれを削除しようとしました:そのno luck: – ssuhat

+0

この方法を試してくださいperent属性を追加する必要はありません –

+0

私の親属性を削除しますが、まだ動作していません – ssuhat

関連する問題