0

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 />
1
  • After further testing, it seems that the route name might have been the issue. When I changed the route to default.list, it worked. Can anyone confirm/elaborate on this? Commented Aug 11, 2014 at 21:00

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

An important detail that I wish I had found on the docs. Thank you so much for clarifying.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.