0

I'm trying to create next and previous buttons for my application.

The pages all use one controller. I'm new to angular, is there any advice on how can I provide navigation for a user to click either forward or backwards through the pages in the controller?

  $routeProvider.
  
    when("/", {

	templateUrl: "partials/home.html", 
	controller: "PageCtrl"}).
	
	when("/c1", {
		templateUrl: "categories/category1.html", 
		controller: "PageCtrl"})
		
	 .when("/category2", {
		 templateUrl: "categories/category2.html", 
		 controller: "PageCtrl"}) 	 
		 
	  .when("/category3", {
	  		templateUrl: "categories/category3.html", 
	  		controller: "PageCtrl"})

	  .when("/category4", {
	  	templateUrl: "categories/category4.html", 
	  	controller: "PageCtrl"})

	  .when("/category5", {
	  	templateUrl: "categories/category5.html", 
	  	controller: "PageCtrl"})

	  .when("/category6", {
	  	templateUrl: "categories/category6.html", 
	  	controller: "PageCtrl"})

	  .when("/category7", {
	  	templateUrl: "categories/category7.html", 
	  	controller: "PageCtrl"})

	  .when("/category8", {
	  	templateUrl: "categories/category8.html", 
	  	controller: "PageCtrl"})

	  .when("/category9", {
	  	templateUrl: "categories/category9.html", 
	  	controller: "PageCtrl"})

2 Answers 2

1

You could add an array to $rootScope with the names of your routes. e.g.

$rootScope.routeNames = ['/category7','/category8']

Then reference the array in your $routeProvider

Then a function will determine the next route based on the current route.

The next button on each page will reference the function to determine the link for the next page.

Alternatively, you could rename your routes as r1, r2, etc then the next route will be easily determined for the next link.

Sign up to request clarification or add additional context in comments.

Comments

0

If you want to ruote through your views when clicking on a button, you just need to define a button as follows:

myFile.html

<button class="myBtn" type="submit" ng-href="#c1"> 
</button>

You just need to use ng-href= "#whereYouWantToGo". You can get rid off # If you really wish, check some answers about it in SO.

Of course, in this way you would be able to define two buttons per each view, one to go back and one to go on. You also should be able to identify these two buttons with two unique ids or names, including them in the pages where you need them and just pass a different path to ng-ref using ng-include or similar, and, you also should be able to keep one CSS class per button type.

I hope I've been helpful.

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.