2

How can I add previous/next buttons/options/links in my example so that I can move forward and backward steps after clicking on those options as per requirement in my third tab for the given content using angularjs or javascript or jquery. I have created fiddle

3
  • 2
    Where do you want to add previous/next button and where it will redirect you Commented Dec 16, 2015 at 5:31
  • in my third tab, it is having couple of buttons(Test, Test1, etc). If we add previous/next options so that we can go forward and backward to display it's content in the same tab. Commented Dec 16, 2015 at 5:33
  • Editted fiddle: jsfiddle.net/mavdhana/6qm7jeo3/3 Commented Dec 16, 2015 at 5:41

2 Answers 2

2

Are you looking for such behavior:

http://jsfiddle.net/6qm7jeo3/5/

I have added a prev and next function. Please have a look at it.

angular.module('TabsApp', [])
  .controller('TabsCtrl', ['$scope', '$location', function($scope, $location) {
    $scope.tabs = [{
      title: 'One',
      url: 'one.tpl.html'
    }, {
      title: 'Two',
      url: 'two.tpl.html'
    }, {
      title: 'Three',
      url: 'three.tpl.html'
    }];

    $scope.currentTab = 'one.tpl.html';

    $scope.onClickTab = function(tab) {
      $scope.currentTab = tab.url;
    }

    $scope.isActiveTab = function(tabUrl) {
      return tabUrl == $scope.currentTab;
    }

    $scope.tab3 = 0;

    $scope.next = function() {
        $scope.tab3 = $scope.tab3 + 1;
    }
    $scope.prev = function() {
        $scope.tab3 = $scope.tab3 - 1;
    }


  }]);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply. Yes this is what I am looking for.
0

Here is the updated fiddle

<ul>
  <li class="navBack" ng-click="navBack()"></li>
  <li ng-repeat="tab in tabs" ng-class="{active:isActiveTab(tab.url)}" ng-click="onClickTab(tab)">{{tab.title}}</li>
  <li class="navNext" ng-click="navNext()"></li>
</ul>

In Controller:

$scope.index = 0;
$scope.navBack = function(tab) {
  if($scope.index > 0)
  {
    $scope.index--;
  }
  $scope.currentTab = $scope.tabs[$scope.index].url;

}

$scope.navNext = function() {
  if( $scope.index < ($scope.tabs.length-1))
  {
    $scope.index++;
  }
  $scope.currentTab = $scope.tabs[$scope.index].url;

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.