Ui Router failing to display content for nested child components

Below is the current code snippet:

let views = { '': 'app/content.html' };

.state('auto', {
    url: '/automated',
    redirectToChild: {
        state: 'auto.index'
    },
    views: view
})
.state('auto.index', {
    url :'',
    templateUrl: '/app/automated/automated.html'
})
.state('auto.visit', {
    url: '/visit',
    views: {
        '': {templateUrl: '/app/automated/visit.html'}
     }
})
.state('auto.visit.create', {
    url: '/create',
    views: {
        '': {templateUrl: '/app/automated/_form.html'}
    }
})

Here is the corresponding HTML:

// index.html
<ui-view></ui-view>


// content.html

 <div class="wrapper">
    <div class="container">
        <ui-view> </ui-view>
    </div>
</div>


// visit.html
<h5>Visit Page</h5>

// form.html
<h5>Visit Form</h5>

Issue at hand: Everything is functioning correctly with this code except when navigating to auto.visit.create state, it displays visit.html instead of '_form.html'.

How can I update the content of visit.html without altering the existing routes?


First Attempt: I changed my auto.visit.create state to auto.visit-create. This corrected the issue but I prefer to keep create nested under auto.visit

Second Attempt: I added a new <ui-view></ui-view> in visit.html, however, when navigating to the create page, it continues to display the content of visit.html.

I have also attempted to follow the example provided here http://angular-ui.github.io/ui-router/sample/#/, unfortunately, with no success.

Answer №1

How do you access the nested views? The notation you're looking for should work perfectly. Make sure to include <ui-view></ui-view> in all parent pages.

Check out the plunker I made as an example; make sure to open the preview in a separate page view to see the generated URLs.


UPDATE

I misunderstood your question, and for that, I apologize. Below is the updated code and plunker that accomplishes what you want. I don't think it's possible to achieve this purely through angular routing, so I used jQuery to implement it. Changes were made on the first layer and second layer.

http://plnkr.co/edit/cxQpu6zS7fifnb0sGvGf?p=preview

Angular Code

(function() {
  angular.module("myApp", ["ui.router"]);

  angular.module("myApp")
    .config(["$stateProvider", "$urlRouterProvider", function($stateProvider, $urlRouterProvider) {
  $urlRouterProvider.otherwise("/");
  $stateProvider
    .state("home", {
      url: "/",
      templateUrl: "blank.html"
    })
    .state("first", {
      url: "/first",
      templateUrl: "firstLayerPage.html"
    })
    .state("first.second", {
      url: "/second",
      templateUrl: "secondLayerPage.html"
    })
    .state("first.second.third1", {
      url: "/third_Page1",
      templateUrl: "thirdLayerPage1.html"
    })
    .state("first.second.third2", {
      url: "/third_Page2",
      templateUrl: "thirdLayerPage2.html"
    })
}]); // end of config
})(); //end of enclosure

Index

<body ng-app="myApp">
  <ul>
    <li><a ui-sref="home">home</a></li>
    <li><a ui-sref="first">First Layer</a></li>
  </ul>
  <h1>Home Page</h1>
  <hr>
  <ui-view></ui-view>
</body>

first layer

<p>This is the first layer of pages.</p>
  <ul>
      <li><a id="showSecondLayer" ui-sref="first.second">Second Layer</a></li>
  </ul>
   <hr>
   <ui-view></ui-view>

   <script type="text/javascript">
     $(document).ready(function(){
       $("#showSecondLayer").click(function(){
         $("#secondLayer").show();
       });
     });
   </script>

second layer

<div id="secondLayer">
  <p>This is the second layer</p>
  <ul>
    <li><a id="thirdP1" ui-sref="first.second.third1">Third Layer Page 1</a></li>
    <li><a id="thirdP2" ui-sref="first.second.third2">Third Layer Page 2</a></li>
  </ul>
  <hr>
</div>
<ui-view></ui-view>

<script type="text/javascript">
  $(document).ready(function(){
    $("#thirdP1").click(function(){
      $("#secondLayer").hide();
    });
    $("#thirdP2").click(function(){
      $("#secondLayer").hide();
    });
  });      
</script>

third layer p1

<p>This is page one of the third level of children</p>
<hr>

third layer p2

<p>This is page two of the third level of children</p>
<hr>

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

Numerous intersecting lines on display within Google Maps

Currently, I am working on displaying multiple flight routes on Google Maps. I have implemented polylines with geodesic to achieve this functionality successfully. However, a challenge arises when more than two flights intersect the same route, causing o ...

Creating dynamic Ionic slides by fetching data from a database

I am currently experimenting with Ionic. Web development is not my strong suit, so I may be a bit off the mark. However, I would like to retrieve data from an SQLite database and display it on an ion-slide-box. Here is what I have attempted: function sel ...

issues with updating a MongoDB collection

One challenge I'm facing with my social media app is that I have two separate collections - one for users and the other for user posts. When I update information in a user's collection, it should also reflect in the corresponding posts (as the po ...

Managing a conditional operator in JavaScript and React - what you need to know!

I am working with the following JavaScript code: const { inverseDirection } = this.props; If the value of inverseDirection is false, I want to execute the following: const dashOffset = dashArray - (dashArray * this.state.percentProgress) / 100; But i ...

Is there a way to bring my popup closer to my button?

Check out my jsfiddle example here: https://jsfiddle.net/annahisenberg/ft10ersb/34/ Currently, I have the following code: <div id="more_options_popup" style={{ left: this.ref.current.offsetLeft - 140 + "px", top: this.ref.current.offsetTo ...

manipulating an iframe on a separate domain

Currently, I am in the process of creating a mobile app using the Ionic framework for my website. Nevertheless, I believe that the issue at hand is not exclusive to Ionic. My goal within the app is to showcase a full-width, full-height iframe loading a sp ...

Node.js meets Blockly for a dynamic programming experience

Can anyone help me figure out how to run blockly on Node.js and have the code execute directly on the server without having to save the XML first and then run it in the background? I've attempted to use various npm modules but haven't found one t ...

Completing Forms Automatically with AngularJS

Hello! I'm just starting out with ng and I need to make an autocomplete textbox that will initiate an AJAX call when the text is changed. The catch is that the minimum length required to trigger the AJAX call is 3 characters. However, once the user en ...

Why does the response.json() method in the Fetch API return a JavaScript object instead of a JSON string?

After using Body.json() to read the response stream and parse it as JSON, I expected to receive a JSON string when I logged the jsonData. Instead, I received a Javascript object. Shouldn't jsonData return a JSON string until we call JSON.parse() to co ...

Adding or removing rows within an array in a hybrid Vue project - a step-by-step guide

Recently, I created a small web application to assist in organizing my project ideas. Check it out here: https://codepen.io/aibrindley/pen/ELXajM Now, I am working on enabling users to add items to the array directly from the interface. It would also be c ...

The way in which notifications for updates are displayed on the Stack Overflow website

Could someone shed some light on how the real-time update messages on this platform are created? For instance, when I am composing a response to a question and a new answer is added, I receive a notification message at the top of the page. How is this fun ...

You can use the following code to retrieve the value of the checked radio button with the name "nameOfradio", but make sure that the radio button

I am attempting to extract the value from a radio button using the following code: document.querySelector('input[name=nameOfradio]:checked').value; However, I would also like to retrieve a value even if none of the radio buttons are checked. Fo ...

Display a loading spinner with ReactJS while waiting for an image to load

I am working on a component that renders data from a JSON file and everything is functioning correctly. However, I would like to add a loading spinner <i className="fa fa-spinner"></i> before the image loads and have it disappear once the ima ...

Unlock the App Store instead of iTunes Store using react-native-version-check

I am currently using react-native-version-check to trigger the opening of the app store or play store if an update is available. However, on iOS it redirects to the iTunes store instead of the desired AppStore location. Below is the code in question: ...

Using Node JS to query data from MySQL and filter a column based on an array of objects

I am dealing with a column in my database that can either be null, contain a single integer, or multiple integers separated by commas. I need to filter specific rows based on this column. However, instead of using a search string, I have an array that coul ...

What is the best way to store an ES6 Map in local storage or another location for later use?

let map = new Map([[ 'a', 1 ]]); map.get('a') // 1 let storageData = JSON.stringify(map); // Saving in localStorage. // Later: let restoredMap = JSON.parse(storageData); restoredMap.get('a') // TypeError: undefined is not a ...

Can you help me pinpoint the tags related to mail?

The email address appears in various locations throughout the page. For instance <div> <p><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a3c2e3c28dd1d6">[email protected]</a></p> </div> ...

Mutual TLS authentication and secure tunneling with ngrok

I am currently working on integrating a Payment Method with Shopify that requires me to validate their client requests using mTLS. Payment apps must utilize mTLS for processing all requests where they act as the server and Shopify as the client. This is ...

What is the best way to add to a variable in jQuery?

I have the following piece of code: var golden_site = '<div id="golden_site"></div>'; $('.form_content').append(golden_site); var lookup = '<input type="text" name="lookup" value="test">'; Can anyone explai ...

No results returned by Mongoose/MongoDB GeoJSON query

I have a Schema (Tour) which includes a GeoJSON Point type property called location. location: { type: { type: String, enum: ['Point'], required: true }, coordinates: { type: [Number], required: true ...