Navigating to the next sibling child in Angular 1 using Ui-router transition

I'm trying to figure out how to effectively transition between sibling states using $state.go() in ui-router.

Imagine a child state with integer-based URLs: /parent/1, parent/2, parent/3 and so on

I want to be able to navigate between these child states with back and next buttons.

Implementation (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) {
        // retrieves active slide from parent controller slides using $stateParams
        $scope.slide = $scope.slides[$stateParams.slide_id];

        // Navigation
        $scope.nextSlide = function () {
          $state.go(''); // <-- what should I put here to move to the next child state?
          // For example, if I am at /parent/2 and want to go to /parent/3?

Maybe something like:

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

^ This is definitely incorrect, but you get the idea of what I'm trying to achieve.

Answer №1

Delving deep into the depths of the internet, I unearthed the answer and am sharing it here:

{
      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});
        };

This valuable information was sourced from an insightful article on routing using $state -->

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be causing the .hover function to malfunction and how can I make it so that the .hover function only applies within the corner radius area?

I am attempting to make circles react to my jquery .hover function. Below is the JavaScript code I am using: jQuery.fn.center = function () { this.css("position","absolute"); this.css("top", Math.max(0, (($(window).height() - this.outerHeight()) / 2) + ...

Can I use npm's jQuery in an old-school HTML format?

I am looking to incorporate jQuery into a project without having to rely on the website or CDN for downloading the library. As someone new to npm, I am curious to know if following these steps would be advisable or potentially problematic down the line. Wh ...

"Exploring the depths of AngularJS with the rootscope and isolated

Here is the snippet of my html and javascript code: <div ng-app="myApp" ng-controller="myCtrl"> {{firstname}} <sample-directive></sample-directive> </div> Javascript: var app = angular.module("myApp", []); app.run(function($r ...

Converting line breaks into a visible string format within Angular

After thorough research, all I've come across are solutions that demonstrate how to display the newline character as a new line. I specifically aim to exhibit the "\n" as a string within an Angular view. It appears that Angular disrega ...

Dynamic item addition feature activated by button on contact form

I am looking to create a form that includes the standard name, phone, email fields as well as a dropdown for selecting products and a text box for inputting quantity. The unique aspect is allowing users to add multiple products (dropdown and quantity textb ...

How do I easily show/hide a submenu in AngularJS with a toggle menu?

After browsing some Stacks, I've come to the realization that I need to create separate directives in order to hide or toggle a menu from its sub-menu items. I want the menu to be hidden when any of the sub-menu items are clicked. However, I can&apo ...

Error encountered when importing a Material-UI component: Unable to load a module from @babel/runtime

Struggling to compile the index.js file with rollup: import React from "react"; import ReactDOM from "react-dom"; import Grid from "@material-ui/core/Grid"; ReactDOM.render( <React.StrictMode> <Grid conta ...

Exploring AngularJS 1.0: Incorporating Dynamic Property Names and Columns into HTML Expressions

I am currently encountering an issue when trying to bind data to angularJs 1.0. I have retrieved the data from the Database using a Pivot Query with Dynamic Column names, however, I am unable to successfully bind the data to the AngularJS html expression ...

Rendering user actions instantly in React.js without waiting for server propagation

I am currently developing a shopping list web application where users can toggle items as 'checked' or 'unchecked'. The flow of data in this application is as follows: click on item checkbox --> send database update request --> ...

Steps to retrieve an array from AJAX request and save it to a JavaScript variable

How can I retrieve the 'this.responseText' array from this function and assign it to a variable named 'teacherIDList'? Any suggestions? var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readySt ...

Utilizing Contentful along with Nuxt.js causes the error message "Required accessToken parameter missing"

I created a webpage that pulls information from Contentful. Although the data is being retrieved correctly, buttons utilizing functions from methods are not working. Additionally, real-time updating of variables (such as using v-model) is not functioning. ...

The React forwardRef Higher Order Component is failing to provide a reference to the container element

I'm currently working on creating a higher order component (HOC) for closing an element when clicked outside of its space, known as a generic close on outside solution. In my understanding, this can be achieved using forwardRef and HOC implementation ...

Step-by-step guide on how to prioritize rendering the login page before the ngView in AngularJS in order to

As I begin my journey with Angular JS, I am eager to implement security measures in my application. My intention is to set up a log-in page as the default landing page for my single page application. Can anyone provide guidance or recommendations on how ...

Upgrading from version 3 to version 5 in d3 does not just update the visualization but also introduces a new one

I attempted to upgrade this d3 visualization from version 3 to version 5, but instead of updating within the existing visualization, it continues to add another visualization below. I included: d3.select(".node").selectAll("*").remove(); d3.select(". ...

Top method in Angular 6 for verifying if a scrollable section has been scrolled to the very bottom

I am searching for a reliable solution in Angular 6 to determine whether a scrollable host component has reached its maximum scroll bottom. Despite my efforts, I have been unsuccessful in finding a functioning example of a function that can detect if a cu ...

When you access the `selectedIndex` property in JavaScript, it will return an object of type `HTMLSelect

I am currently working on a piece of code that retrieves the value from dropdown list items and then displays it in the document. To proceed, please select a fruit and click the button: <select id="mySelect"> <option>Apple</option ...

Failure to load a picture does not trigger onError in the onLoad function

Is there a way to ensure that an image always loads, even if the initial load fails? I have tried using the following code snippet: <img class="small" src="VTVFile4.jpg" onload="this.onload=null; this.src='VTVFile4.jpg?' + new Date();" alt=" ...

"Empty $stateParams Issue Encountered in Angular UI-Router While Using My Directive

I have developed a unique directive in my angular application for a custom navbar. The controller of this directive utilizes $stateParams to access a variable named lang, as shown below: .config(function($stateProvider, $urlRouterProvider, LANG) { $u ...

When a node using express encounters :id, it is directed to a specific location

Currently, I am in the process of creating a small API collection to familiarize myself with nodejs using express. In my project, I have included the line app.use("/v1/phrases", phraseRouter); Within the router file, the code looks like this: co ...