The nested view in ui-router fails to load correctly

Hi there, I've developed a simple app with multiple views.

Here are the different views in my app:

1. Settings - Main View.

2. Profile - Sub view, nested under Settings View.

3. Account - Sub View, also nested under Settings View.

I want the app to start from the profile page, so I included this code:

$urlRouterProvider.otherwise('/profile');

However, when I try to run the app, I'm getting a blank screen instead of seeing the proper view (settings.profile).

To make it easier for other developers to help me troubleshoot, I've shared my code on Plunker: https://plnkr.co/edit/RFP5dUNV876cy8vRDuvL?p=preview

The main portion of my code looks like this:

/**
*  Module
*
* Description
*/
var app = angular.module('app', ['ui.router'])

app.controller('mainCtrl', ['$scope', function($scope){
    $scope.title="Index Page";
}]);

app.controller('ProfileController', ['$scope', function($scope){
    $scope.title="Profile Page";
}]);

app.controller('AccountController', ['$scope', function($scope){
    $scope.title="Account Page";
}]);

app.controller('SettingsController', ['$scope', function($scope){
    $scope.title="Settings Page";
}]);

app.config(function($stateProvider, $urlRouterProvider) {
    $stateProvider
        .state('settings', {
            url: '/settings',
            templateUrl: 'settings.html',
            controller: 'SettingsController'
        })
        .state('settings.profile', {
            url: '/profile',
            templateUrl: 'profile.html',
            controller: 'ProfileController'
        })
        .state('settings.account', {
            url: '/account',
            templateUrl: 'account.html',
            controller: 'AccountController'
        });
    $urlRouterProvider.otherwise('/profile');
});

Answer №1

Modify the .otherwise function to:

$urlRouterProvider.otherwise('/settings/profile');

Given that the other routes are nested within the settings state, you can only navigate to the nested views using the <ui-view> in the settings.html file. The URLs are also nested within each other when the url parameter is defined in both, hence making it necessary to use /settings/profile.

Revised Plnkr link

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 is the best way to export a React Material-UI component with two separate styles objects in Material-UI V1?

We are currently utilizing material-ui version 1 and composing Higher Order Components (HOC) with the recompose utility. Our issue arises from having two separate styles objects - one defined within the component itself, and another general style object th ...

AJAX/PHP causing delays due to lag problems

I've been trying to implement an asynchronous call in my PHP script, but I keep running into the same issue: "Maximum call stack size exceeded." This is causing severe lag on my site and I suspect there might be a loop somewhere in my code that I just ...

What is the method to transfer a declared object from a .ejs file to my index.js file?

I have a simple script embedded in my .ejs file. The script captures input data from the user and stores it in an object. Now, my goal is to send this object to my index.js file, where I plan to utilize the data with a node module called coap (similar to ...

Employ the $scope.go() method within a function written in JavaScript

I am working with some HTML code that looks like this <body ng-app="app" ng-controller="IndexCtrl" id="indexBody"> <h1>test</h1> </body> Next, in a JavaScript function, I retrieve the scope like so function myFx() { ...

Strategies for managing events within functional React components without relying on mutative operations

Based on insights from Cam Jackson, the recommendation is to utilize Redux and create small, stateless functional components. For example: const ListView = ({items}) => ( <ul> {items.map(item => <ItemView item={item}/>)} ...

Creating a multi-level signup page in Angular 4 using Bootstrap

Currently, I am working with angular 4 and bootstrap 4 to create a multi-level sign-up page. One of the challenges I am encountering is how to properly include a JavaScript file into my angular project. import '../../../assets/js/js/multiform.js&apo ...

Editing a video directly within the browser prior to uploading it

For my new video upload platform, I am looking to give users the ability to trim their videos directly in their browser before uploading to the cloud storage. Can anyone suggest a Javascript solution for this feature? ...

The provider for authentication, which is linked to the AuthenticationService and subsequently to the loginControl, is currently unidentified

Attempting to implement an authentication service in my application, I encountered an error when trying to call it within my controller: !JavaScript ERROR: [$injector:unpr] Unknown provider: AuthenticationServiceProvider <- AuthenticationService <- ...

Buttons failing to vanish after being clicked

Hey there! I've been working on a code snippet that displays 2 buttons based on the user's query, such as 'Yes' and 'No'. The idea is that once a button is clicked, both buttons should vanish. To achieve this functionality, I ...

Having difficulty displaying nested arrays in AngularJS

Understanding JSON Data in AngularJS As I delve into the world of AngularJS, I've encountered a minor roadblock when it comes to fetching JSON data. <html> <head> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/boots ...

Exploring AngularJS's Unique Features: Isolated Scope and Controller Connection

Currently, I am diving into Angular and endeavoring to develop a Phone Message Log application utilizing directives. The concept is simple - the user inputs a message, clicks a button, and it gets displayed in a "Message" log below. The challenge I'm ...

Creating a continuous loop in JQuery when clicking on a table row

I seem to be encountering an issue with what appears to be an infinite loop. My problem arises while trying to create a table dynamically using Ajax. Each row of the table contains a button alongside a thumbnail image and some text. I wish for the button ...

Using v-model with an input file is not supported

Is there a solution for not being able to use v-model in an input tag with type="file"? Here is an example of the HTML code causing this issue: <input v-model="imageReference" type="file" name="file"/> ...

The counter variable does not function properly within a setInterval function

I have encountered an issue with my scroll-counter variable inside the setInterval function. It increments by 1 each time the setInterval function runs, which is supposed to happen 20 times before stopping. However, I noticed that the value of this variabl ...

Click the "Login" button using Jquery to gain access

Whenever I hit the Login button, a 500 Internal server error pops up in the console. Can someone guide me on the correct way to perform a POST request using jQuery? I would really appreciate any help. <button class="login100-form-btn" type=& ...

Iframe not displaying Base64 encoded PDF in Chrome App

Currently, I am in the process of developing a Chrome App that essentially acts as a wrapper for the main app within a webview. The webview sends a Base64 encoded PDF as a message to the app, which then creates a hidden iframe and loads the PDF into the fr ...

Jasmine spies call through problem detected

I can't seem to get my code to work properly and I keep encountering this error: TypeError: undefined is not an object (evaluating 'GitUser.GetGitUser('test').then') ... Check out the code snippets below: app.controller(&apo ...

Error 500 on Firebase: Issue solving "firebase" in "firebase.js" not resolved

Struggling to incorporate Firebase into my latest React project, I keep encountering the dreaded "The development server returned response error code: 500." Despite creating a firebase.js file to house my Firebase configuration details, I am at a loss as ...

An issue has been identified where the Export to Excel and PDF functionality is not functioning properly within a Datatable after applying a

I am using multiple select option filtering with ajax, jQuery, and PHP in a datatable. The records are being filtered correctly, but after changing the select option, the Export to Excel/ PDF functionality is not working properly. Note:- (1) It always do ...

Why does running the code result in the error mentioned above?

Uncaught ReferenceError: Unable to process binding "value: function (){return sumValBinding }" Message: sumValBinding is not defined Here is the HTML code snippet: <div class="form-group"> <label for="inputdefault">First numbe ...