Encountering a problem with $state.go in conjunction with ui-router: the URL successfully transitions to the new state, but the HTML content for the new view fails to

I'm facing a situation where I have an index.html page with two views: View1.html on the left and view2.html on the right. However, when a record is selected in the left view, I want to switch the right view from view2.html to view3.html.

Currently, I am utilizing the following code snippet:

$scope.$state.go('reg.detail', { 'id': item.Id });

To change the view from View2.html to View3.html

Although the URL changes to details/{id}, the UI (html markup) does not update to view3.html. This means that the controller for view3 is also not being triggered (I have omitted the controller code below for simplicity).

var app = angular.module('app', ['ui.router']);

(function () {
    'use strict';

    angular
        .module('app')
        .config(['$stateProvider', '$locationProvider', '$urlRouterProvider',
            function ($stateProvider, $locationProvider, $urlRouterProvider) {
                $urlRouterProvider.otherwise('/');
                $stateProvider
                .state('reg', {
                    url: '/',
                    views: {
                        'leftPanel': {
                            templateUrl: 'app/View1.html',
                            controller: 'view1Ctrl'
                        },
                        'rightPanel': {
                            templateUrl: 'app/View2.html',
                            controller: 'view2Ctrl'
                        }
                    }
                })
                .state('reg.detail', {
                    url: 'detail/:id',
                    parent: 'reg',
                    templateUrl: 'app/View3.html',
                    controller: 'view3Ctrl'
                   
                })

            }]);

})();


(function () {
    'use strict';

    angular
        .module('app')
        .controller('appCtrl', appCtrl);

    appCtrl.$inject = ['$scope', '$rootScope','$state'];

    function appCtrl($scope, $rootScope, $state) {


    }
})();
index(main) page code :
<div auto-size>
    <div ui-view="leftPanel" >Left panel is loading...</div>
    <div ui-view="rightPanel" >Right panel is loading...</div>
</div>

Any assistance would be greatly appreciated. Please let me know if you need more code details.

Answer №1

To start off, one method is to insert a targeted ui-view into view 2:

<div>

  <h3>View 2</h3>

  <hr />
  // placeholder in the view 2 for view 3
  <div ui-view=""></div>

</div>

You can see a fully functional example here

Another approach involves targeting the root view placeholder 'rightPanel@' within the nested state 'reg.detail':

.state('reg.detail', {
      url: 'detail/:id',
      parent: 'reg',
      views : {
        // this will truly replace the view 2 with view 3
        'rightPanel@': {
          templateUrl: 'app/View3.html',
          controller: 'view3Ctrl',
        }
     }
})

A live demonstration can be found here

For more information on absolute naming (targeting a different ui-view than the parent), you may want to check out this discussion on Angularjs ui-router not reaching child controller

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

How can I manage the transfer of items between lists in angular-ui sortable?

I am currently utilizing angular-ui sortable version 1.2 My goal is to manage the transfer of an item from one list to another and ensure that the back-end gets updated accordingly. The jquery-ui-sortable plugin offers various events, such as the receive ...

The Angular model does not automatically refresh when the Space or Enter key is pressed

Having an issue with my editable div and the ng-trim attribute. Even though I have set ng-trim to false, pressing SPACE or ENTER does not increment the string length by one in the div below. Using Angular 1.3.x and wondering if anyone has any ideas on how ...

Execute an Angular factory AJAX request with each change in route

I operate a factory where I utilize a function called getExpenseList that performs an ajax call to fetch data from the expense table. Currently, I have two routes set up - one for listing expenses and another for adding new expenses. However, whenever I n ...

loop through nested arrays

My goal is to use ng repeat in Angular to iterate through a child array of a multidimensional array. The json object I am working with is as follows: $scope.items = [{ "id":1, "BasisA":"1", "Basis":true, "personSex": ...

What is preventing me from binding ng-click to my element?

I've encountered an issue where the ng-click event is not activating on my element. Despite using the in-line controller script as shown below, I am unable to trigger my alert. Are there any integration issues that I should be mindful of? What could p ...

What is the best way to add this dependency to an AngularJS application?

I am struggling to properly implement the injection of this dependency: https://cdnjs.cloudflare.com/ajax/libs/angularjs-dropdown-multiselect/2.0.0-beta.10/src/angularjs-dropdown-multiselect.js within my project. This is the current dependency injection s ...

Organizing complex data structures in Python

My program takes 3 keys and values per project for 5 different environments to create a JSON file. However, the projects must have unique names within each environment, distinguished by a tag at the end. The project names do not follow generic labels like ...

Issues with Angular.js controller functionality

I am currently in the process of learning Angular and have been following the Intro to Angular videos provided on the official Angular website. However, I seem to be encountering an issue with my code that I can't quite figure out. The error message I ...

Upgrade from AngularJS 1.x to the latest version of Angular, AngularJS 2.x

Currently in the process of mastering AngularJS 2 in order to transition my applications from Angular 1.x. The differences between the two versions are quite significant. Can you please share the advantages of upgrading from Angular 1 to Angular 2? I am ...

What could be the reason for ng-transclude not functioning as anticipated in AngularJS?

Seeking help with my simple directed isolated scope. I have followed a transclude tutorial but it's not working as expected. I want to display "dd" and a test together, how can I achieve this? var app =angular.module('app',[]); app.direc ...

Angular DataTables with support for Webpack

Having an issue related to webpack and angularjs datatables. Encountering the error message: Error: Cannot find module "./dist/plugins/bootstrap/datatables.bootstrap.css" Listed below is my configuration: This is my Webpack setup: Please inform me if ...

Reiterate list of inquiries using InquirerJS

How can the questions be reset or have a specific answer lead to another previous question? var questions = [{ { name: 'morefood', message: 'Do you want more food?', ...

Guide to querying MongoDB for data based on date using Express

I am attempting to retrieve data from a mongoDB collection based on the creation date. Date format for retrieving data: yyyy-mm-dd (e.g. 2015-04-14) Format stored in collection: timestamp: "2015-04-13T17:50:48.761Z" Controller : $scope.getExpenc ...

The implementation of local JSON instead of external JSONP in Angular

I am exploring the option of storing a json-file on the same server as my Angular app. I am wondering about how I can modify this code to read from a locally stored json file: ergastAPI.getDrivers = function() { return $http({ method: 'GET&apos ...

The ng-repeat directive seems to be malfunctioning and is not

Hey guys, I need some help with my code. The ng-repeat function should generate a list, but for some reason, it's not showing anything on the screen. Can anyone take a look and see if they can find the issue? <!DOCTYPE html> <html lang="en" ...

Issue encountered: [$injector:modulerr] while attempting to utilize the $modal functionality

I recently started exploring Angular and attempted to implement a modal window by following the guide at However, upon loading the page, I encountered the following error - Error: [$injector:modulerr] http://errors.angularjs.org/1.3.15/$injector/moduler ...

What are some examples that illustrate the differences between ng-if, ng-show, and ng-hide

While exploring ng-if, ng-show, and ng-hide, I realized that they all seem to serve a similar purpose. Why are there three directives when one might suffice? ...

Can you provide the Angular JS alternative for executing a POST request similar to this Curl command?

Trying to translate a Curl command into Angular JS code has been a challenge for me as a newcomer to AngularJS. This specific instance involves a mobile app built on the ionic framework, which utilizes Angular JS. The original curl command looks like this ...

Ways to select a service in AngularJS depending on a specific parameter

In my code, I have a set of functions in two different services that are being used across multiple controllers. However, at any given point, I only use one service out of the two. Currently, I am manually changing the service name in all instances whenev ...

AngularJS: Understanding the difference between ng-show and using display:none

I recently encountered a scenario where I needed to hide an HTML element by default using CSS. Here's how I did it: HTML: <div class="box"> </div> CSS: .box { display: none; } However, I wanted to be able to show and hide the elem ...