Brk Brk - 11 months ago 59
Javascript Question

ui-router nested view doesn't get loaded properly

Hey I have a simple app which I have created.

The app has the following views

1.Settings - Main View.

2.Profile - Sub view, child of Settings View.

3.Account - Sub View, child of Settings View.

I want the application to start from profile page, therefore I wrote the following code:


But apparently noting is happen, I got a blank screen and can't see the view properly(settings.profile).

I have added my code to a plunker to make things more convenient and accessible for other developers which can help me solve my problem.

Main main code is 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) {
.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'

Answer Source

Change the .otherwise function to:


Since the other routes are nested within settings state, you can only access the nested views via the <ui-view> in settings.html. The urls are also nested within each other if url parameter is defined in both, so /settings/profile is required.

Updated Plnkr