angularjs - confusion about nested named views with angular-ui-router

Ciel

Using angular-ui-router, an external routing plugin for angular found here, I am attempting to understand how the nested named views work. I got the initial demos working fine, but tried to make some modifications, like this;

$stateProvider
   .state('default', {
      url: "/default",
      views: {
         "viewA" : { templateUrl: "angular/partials/default.A.html" },
         "viewB" : { templateUrl: "angular/partials/default.B.html" }
      }
   })
   .state('state1.list', {
      url: "/state1list",
      views: {
         "viewAList" : { 
            templateUrl: "angular/partials/state1.list.html",
            controller: function($scope) {
               $scope.items = ["A", "List", "Of", "Items"];
            }
         }
      }
   });

The idea is that I am setting the list contents to a named view that is nested inside of the default.A.html file.

Error

The error message I receive is this;

Error: Could not resolve 'state1.list' from state 'default'

HTML

The html looks like this;

index.html

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

angular/partials/default.A.html

<h1>Default.A.HTML</h1>
<hr />
<a ui-sref="state1.list">Show List</a>
<div ui-view="viewAList"></div>

angular/partials/state1.list.html

<h3>List of State 1 Items</h3>
<ul>
    <li ng-repeat="item in items">{{ item }}</li>
</ul>

angular/partials/default.B.html

<h1>Default.B.HTML</h1>
<hr />
Sid

The problem is that when you supply state1.list, the 'state1' state is considered to be the parent of the 'state1.list' state. But you don't have a state named 'state1'. Once you change it to 'default.list', the inferred parent is 'default', which works because you do have a 'default' state. If you created a new state named 'state1' and then another one named 'state1.list' then that would work as well.

Naming Your States (From https://github.com/angular-ui/ui-router/wiki/Nested-States-%26-Nested-Views)

No two states can have the same name. When using dot notation the parent is inferred if it is not explicitly provided, but this doesn't change the state name. When not using dot notation, the parent must be explicitly provided, but you still cannot name any two states the same, for example you can't have two different states named "edit" even if they have different parents.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AngularJS UI router: How to configure nested named views?

From Dev

Angular UI router nested views

From Dev

Angular-Ui-Router, nested named views - what am I doing wrong?

From Dev

angular-ui-router nested views

From Dev

Recursive ui router nested views

From Dev

Angular ui-router nested views separated templates and controllers

From Dev

Angular UI router nested views when targeting parent

From Dev

Angular ui router multiple named views for all states

From Dev

Angular UI Router Nested Views Issue

From Dev

Angular-UI Router: Nested Views Not Working

From Dev

AngularJS UI router named views lazy loading

From Dev

Angular UI Router views with states

From Dev

Conditional angular ui router views

From Dev

angular-ui-router nested named views with typescript

From Dev

UI-Router multiple named views not working

From Dev

angularjs - ui-router multiple nested views

From Dev

Recursive ui router nested views

From Dev

Problems with nested views using angular-ui-router

From Dev

Angular ui-router: selectively populating templates in named views

From Dev

AngularJS UI router named views lazy loading

From Dev

angular UI-Router nested views on a page

From Dev

ui router nested views condtions

From Dev

Conditional angular ui router views

From Dev

angular ui-router nested views can't display?

From Dev

Angular-UI Router Nested Views Not Working for some Mobile browsers

From Dev

UI Router nested views

From Dev

Multiple Named Views in UI Router

From Dev

Angular UI-Router: nested views

From Dev

Getting nested views to work with multiple modules in AngularJS and ui-router