Navigating with UI-Router within a single view for both viewing and editing purposes

I have been encountering an issue with changing states between the view page and edit page using UI-Router. Here are some of the things I have attempted:

Controller:

$stateProvider
        .state('showViewA', {
            views: {
                " ": {
                    template: "default.html",
                    controller:"DefaultController.ts"
                     },
                "viewB@showViewA": {
                    template: "viewPage.html",
                    controller:"DefaultController.ts"
                    }
            } 
        }) 
    .state('showViewA@EditshowViewA', {
            views: {
                " ": {
                    template: "defaultEdit.html",
                    controller:"DefaultEditController.ts"
                     }                 
            } 
        }) 
    .state('showViewA@ViewshowViewA', {
            views: {
                " ": {
                    template: "defaultShow.html",
                    controller:"DefaultShowController.ts"
                     }                 
            } 
        }) 

Within default.html, I am only rendering the view that should be visible when initially opening the page, i.e., the edit page.

<div ui-view="showViewA"></div> 

This displays the edit page. After saving changes on the edit page, I want to transition to the view page specified in state showViewA@ViewshowViewA, but the redirect is not happening. Can you help me identify where I went wrong?

Answer №1

Visit this plunker

Imagine that this represents the default.html content:

<div >
  <h2>The default view (layout)</h2>

  <b>placeholder for viewB</b>
  <hr />

  <div ui-view="viewB"></div>      
</div>

Next, let's update our state configuration to correspond with these links:

 <a ui-sref="showViewA">
 <a ui-sref="showViewA.EditshowViewA">
 <a ui-sref="showViewA.ViewshowViewA">

Here is the modified states definition (new lines represent changes - old lines are commented out).

Parent state with inner view injected into ui-view="viewB" placeholder/anchor

    .state('showViewA', {
      url: '/',
      views: {
        //" ": {
        "": {
          //template: "default.html",
          templateUrl: "default.html",
          //controller:"DefaultController.ts"
          controller: "DefaultController"
        },
        "viewB@showViewA": {
          //template: "viewPage.html",
          templateUrl: "viewPage.html",
          //controller: "DefaultController.ts"
          controller: "DefaultController"
        }
      }
    })

Children injecting their views into the same ui-view="viewB"

  //.state('showViewA@EditshowViewA', {
  .state('showViewA.EditshowViewA', {
    views: {
      //" ": {
      "viewB": {
        //template: "defaultEdit.html",
        templateUrl: "defaultEdit.html",
        //controller:"DefaultEditController.ts"
        controller: "DefaultEditController"
      }
    }
  })
  //.state('showViewA@ViewshowViewA', {
  .state('showViewA.ViewshowViewA', {
    views: {
      //" ": {
      "viewB": {
        //template: "defaultShow.html",
        templateUrl: "defaultShow.html",
        //controller:"DefaultShowController.ts"
        controller: "DefaultShowController"
      }
    } 
  })

Try it out here

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

Is it possible to store Socket.IO responses in a cache for quicker retrieval?

Consider this scenario where I have a websocket implementation shown below: let itemsArray = []; function fetchData() { itemsArray = await db.query(`SELECT * FROM Items`); } function emitData() { io.sockets.in("room_foo").emit("data", JSON.stringify ...

Guide on implementing ng-change in a select dropdown for dynamically populating data

As a newcomer to AngularJS, I am currently working on an Ionic app where I am facing an issue with populating select options based on the selection of the first option. The variable selected in the first select option is not being processed correctly to re ...

I have added the same directive to both of my HTML files

Hello, I am facing an issue with a directive that I have included in two HTML files. The 'app' is set as ng-app. <dir auto=""></div> The code for the directive is as follows: app.directive("auto", function() { scope: { arr : ...

Error: Unable to locate module: 'fs' in Next.js

import nookies from 'nookies'; import { firebaseAdmin } from "../firebaseAdmin"; import { TChildren } from "../types/app/app.types"; interface Props { children: TChildren; } export default function ProtectedRoute(props ...

Execute the cucumber tests based on tags or run all the tests

I am facing challenges when it comes to running cucumber tests. I aim to execute either all scenarios if tags are not provided as a CLI argument, or specific scenarios based on the passed tags as CLI arguments. Here is my configuration file: module.exports ...

Secure API Calls with Prismic while Keeping Access Tokens Hidden

As I delve into the world of building a Vue.js web app, I find myself faced with the challenge of making calls to my Prismic repository without exposing my access token. The Rest API approach outlined here seems promising, but I'm at a loss on how to ...

How can JQuery be used to implement "scrolling" buttons and automatically update the main page with fresh data?

I am attempting to achieve the following: 1 - Use jQuery to update index.html with the content from output.html (only update when there are differences in data, and ideally only update the parts that have changed). 2 - Add two buttons in the header ...

Adding flair to the encompassing container

Below is the HTML code that I am working with: <div class="um-field field-date"> <p class="form-row " id="date_field"> <label class="date"> <input data-label="Date" data-value="" type="date" class="input-date um-frontend-f ...

Updating Sencha list itemTpl on the fly

Is there a way to dynamically change the itemTpl in a Sencha list to adjust the visibility of a column based on certain conditions? Your assistance would be greatly appreciated. ...

How about utilizing node.js as a peer for WebRTC?

Are there any available modules for utilizing node.js as a peer in WebRTC? I am interested in using WebRTC in a client/server manner rather than P2P for its ability to send packets unreliably (i.e. avoiding the delay caused by TCP's guarantee of packe ...

Updating the footer of a React application using Material UI Grid

Having some trouble customizing the footer in a React Material-UI grid. Refer to the image below for details. Any ideas on how to change the: 1 row selected? Thank you! ...

unable to execute grunt post npm installation

I'm having trouble getting grunt to work on my system. I tried installing it using npm install grunt -g It appears to have installed successfully - <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4b3a6a1baa094e4fa0bbe7 ...

Should the article ID be sent to the ajax file, or should the ajax file retrieve the article ID directly? This dilemma arises in a

I am trying to pass the current article ID to an ajax file. The URL of the ajax file is something like www.web.com/plugins/system/ajax.php, so using JRequest::getInt(id) always returns 0 integer. However, in a non-ajax file, I can get the ID the same way. ...

The TypeScript compiler is indicating that the Observable HttpEvent cannot be assigned to the type Observable

Utilizing REST API in my angular application requires me to create a service class in typescript. The goal is to dynamically switch between different url endpoints and pass specific headers based on the selected environment. For instance: if the environmen ...

The trick to keeping a div open without it closing until the page is refreshed

I am currently working on a project that involves creating an interactive map with dots. Each dot, when clicked, should trigger the display of a form related to that specific dot within a <div>. My challenge is ensuring that once a dot is clicked an ...

Utilize Selenium to extract information from a webpage, including content that is dynamically generated through JavaScript

Currently, I am facing a dilemma: my desire is to extract information from a webpage (for example, this one) regarding the apps that are available, and then store this data into a database. In my quest to achieve this task, I have opted to use crawler4j t ...

No content sent in the request body while implementing fetch

Attempting to send graphql calls from a React component to a PHP server using the fetch method for the first time. The setup involves React JS on the client-side and Symfony 4 on the server-side. Despite indications that data is being sent in the browser ...

Using Javascript within a PHP file to generate JSON output

Can you integrate Javascript code within a PHP file that utilizes header('Content-Type: application/json'); to produce output in JSON format? UPDATE: I'm attempting to modify the color of a CSS class when $est = 'Crest', but the J ...

Unfortunately, CORS is preventing me from sending a POST request through AJAX

I'm currently working on integrating an API into my website. I'm attempting to send a POST request with JSON data, but I keep encountering an error code when trying to make the request. Interestingly, sending the request using curl does not pose ...

Neglect to notify about the input text's value

Having trouble retrieving the text from a simple <input id="editfileFormTitleinput" type="text>. Despite my efforts, I am unable to alert the content within the input field. This is the code snippet I've attempted: $('#editfileFormTitleinp ...