【问题标题】:Angular 1 Ui-router - transition to next child siblingAngular 1 Ui-router - 过渡到下一个子兄弟
【发布时间】:2016-12-08 13:36:50
【问题描述】:

我不能从关于如何使用 $state.go() 有效地在兄弟状态之间转换的关于 ui-router 的文档中弄清楚

考虑一个 url 基于整数的子状态: /parent/1、parent/2、parent/3 等

我需要使用后退和下一步按钮在子状态之间导航。

工作(routes.js):

// child states: /parent/1, /parent/2, /parent/3 etc
    {
      name: '3-INT-TOTM.detail',
      url: '/:slide_id',
      templateUrl: 'app/html-partials/part-1/3-int.detail.html',
      params: {
        score: null
      },
      controller: function ($scope, $stateParams, $log, $location, $state) {
        // sorts active slide from parent controller slides based on $stateParams
        $scope.slide = $scope.slides[$stateParams.slide_id];

        // Navigation
        $scope.nextSlide = function () {
          $state.go(''); // <-- what goes in here to go forward a child
          // i.e if I'm here: /parent/2 and I want to go to /parent/3?

可能是这样的:

$state.go('3-INT-TOTM.detail'[$stateParams.slide_id] +1 );

^ 肯定错了,但你可以看到我要去哪里。

【问题讨论】:

    标签: javascript angularjs routing angular-ui-router state


    【解决方案1】:

    在网上认真挖掘后自己发布答案:

    {
          name: '3-INT-TOTM.detail',
          url: '/:page',
          templateUrl: 'app/html-partials/part-1/3-int.detail.html',
          params: {
            score: null,
            page: {
              value: '0',
              squash: true
            }
          },
          controller: function ($scope, $stateParams, $log, $location, $state) {
    
            $scope.page = parseInt($stateParams.page, 10);
            $scope.slide = $scope.slides[$stateParams.page];
    
            // Navigation
            $scope.prevSlide = function () {
              $state.go('.', {page: $scope.page - 1});
            };
            $scope.nextSlide = function () {
              $state.go('.', {page: $scope.page + 1});
            };
    

    取自一篇关于此类路由 $state 东西的精彩文章 --> http://www.codelord.net/2015/06/20/simple-pagination-and-url-params-with-ui-router/

    【讨论】:

      猜你喜欢
      • 2017-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多