2

I'm new to ui-router and can't get layout.directory.teams or layout.directory.people to load their respective templates. I expect those templates to be loaded in the ui-viewon the layout state's template.

/dashboard works fine...the dashboard.html template is loaded in the ui-view in content.html template.

/directory/teams doesn't load the teams.html template.

/directory/people doesn't load the people.html template.

.state('layout', {
    abstract: true,
    templateUrl: "components/common/content.html"
})
.state('layout.dashboard', {
    url: "/dashboard",
    controller: 'DashboardCtrl',
    controllerAs: 'dashboard',
    templateUrl: "app/features/dashboard/views/dashboard.html",
})
.state('layout.directory', {
    abstract: true,
    url: "/directory"
})
.state('layout.directory.teams', {
    url: "/teams",
    controller: 'DirectoryCtrl',
    controllerAs: 'directory',
    templateUrl: "app/features/directory/views/teams.html",
})
.state('layout.directory.people', {
    url: "/people",
    controller: 'DirectoryCtrl',
    controllerAs: 'directory',
    templateUrl: "app/features/directory/views/people.html",
})
3
  • 3
    Add template: "<div ui-view></div>" to layout.directory state. A child state renders in the template of its parent... so, the parent must have ui-view Commented Oct 17, 2015 at 22:15
  • Well that was easy enough...it worked :) If you add that as an answer I can accept it. Is that because the child states need to inject their template into their direct parent's ui-view instead of the top level ui-view (in my case, layout)? Commented Oct 17, 2015 at 22:19
  • Yes... added as an answer Commented Oct 17, 2015 at 22:23

1 Answer 1

6

A child state renders its template in the template of its parent where ui-view directive is, even if the parent is abstract.

So, in your case, add ui-view to the template of layout.directory state:

.state('layout.directory', {
    abstract: true,
    url: "/directory",
    template: "<div ui-view></div>"
})
Sign up to request clarification or add additional context in comments.

Comments

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.