2016-04-08 63 views
1

嗨,我有一个问题,父母状态不活跃时,孩子打电话。Angular UI路由器的父母状态不活跃

我使用具有ui-sref-active功能的ui路由器。

这里是我的路由器代码:

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

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

我使用NG重复,因为有很多的菜单。

问题是当我拨打/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?因为我通常在这样的对象之后加逗号。我已经尝试删除它,它的运气不好:) – ssuhat

+0

请尝试这种方式,不需要添加perent属性 –

+0

我删除我的父属性,但仍然不工作 – ssuhat

相关问题