繁体   English   中英

Angular UI-router父状态未激活

[英]Angular UI-router parent state not active

嗨我遇到一个问题,当孩子打电话时父母状态不活跃。

我正在使用带有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:

 <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-repeat,因为有足够的菜单。

问题是当我调用/customersui-sref-active正常工作。 但是当/customers/birthday call,ui-sref-active消失了。

以下截图:

1 2

任何建议如何使其工作?

提前致谢!

可能是因为你的筑巢路线。 尝试这样的事情:

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

    })

我终于解决了。

在我

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM