Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8679803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:04:27+00:00 2026-06-12T21:04:27+00:00

My question involves how to go about dealing with complex nesting of templates (also

  • 0

My question involves how to go about dealing with complex nesting of templates (also called partials) in an AngularJS application.

The best way to describe my situation is with an image I created:

AngularJS Page Diagram

As you can see this has the potential to be a fairly complex application with lots of nested models.

The application is single-page, so it loads an index.html that contains a div element in the DOM with the ng-view attribute.

For circle 1, You see that there is a Primary navigation that loads the appropriate templates into the ng-view. I’m doing this by passing $routeParams to the main app module. Here is an example of what’s in my app:

angular.module('myApp', []).
    config(['$routeProvider', function($routeProvider) {
        $routeProvider.                     
            when("/job/:jobId/zones/:zoneId", { controller: JobDetailController, templateUrl: 'assets/job_list_app/templates/zone_edit.html' }).
            when("/job/:jobId/initial_inspection", { controller: JobDetailController, templateUrl: 'assets/job_list_app/templates/initial_inspection.html' }).
            when("/job/:jobId/zones/:zoneId/rooms/:roomId", { controller: JobDetailController, templateUrl: 'assets/job_list_app/templates/room_edit.html' })       

    }]);

In circle 2, the template that is loaded into the ng-view has an additional sub-navigation. This sub-nav then needs to load templates into the area below it – but since ng-view is already being used, I’m not sure how to go about doing this.

I know that I can include additional templates within the 1st template, but these templates are all going to be pretty complex. I would like to keep all the templates separate in order to make the application easier to update and not have a dependency on the parent template having to be loaded in order to access its children.

In circle 3, you can see things get even more complex. There is the potential that the sub-navigation templates will have a 2nd sub-navigation that will need to load its own templates as well into the area in circle 4

How does one go about structuring an AngularJS app to deal with such complex nesting of templates while keeping them all separate from one another?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:04:28+00:00Added an answer on June 12, 2026 at 9:04 pm

    Well, since you can currently only have one ngView directive… I use nested directive controls. This allows you to set up templating and inherit (or isolate) scopes among them. Outside of that I use ng-switch or even just ng-show to choose which controls I’m displaying based on what’s coming in from $routeParams.

    EDIT Here’s some example pseudo-code to give you an idea of what I’m talking about. With a nested sub navigation.

    Here’s the main app page

    <!-- primary nav -->
    <a href="#/page/1">Page 1</a>
    <a href="#/page/2">Page 2</a>
    <a href="#/page/3">Page 3</a>
    
    <!-- display the view -->
    <div ng-view>
    </div>
    

    Directive for the sub navigation

    app.directive('mySubNav', function(){
        return {
            restrict: 'E',
            scope: {
               current: '=current'
            },
            templateUrl: 'mySubNav.html',
            controller: function($scope) {
            }
        };
    });
    

    template for the sub navigation

    <a href="#/page/1/sub/1">Sub Item 1</a>
    <a href="#/page/1/sub/2">Sub Item 2</a>
    <a href="#/page/1/sub/3">Sub Item 3</a>
    

    template for a main page (from primary nav)

    <my-sub-nav current="sub"></my-sub-nav>
    
    <ng-switch on="sub">
      <div ng-switch-when="1">
          <my-sub-area1></my-sub-area>
      </div>
      <div ng-switch-when="2">
          <my-sub-area2></my-sub-area>
      </div>
      <div ng-switch-when="3">
          <my-sub-area3></my-sub-area>
      </div>
    </ng-switch>
    

    Controller for a main page. (from the primary nav)

    app.controller('page1Ctrl', function($scope, $routeParams) {
         $scope.sub = $routeParams.sub;
    });
    

    Directive for a Sub Area

    app.directive('mySubArea1', function(){
        return {
            restrict: 'E',
            templateUrl: 'mySubArea1.html',
            controller: function($scope) {
                //controller for your sub area.
            }
        };
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read almost every Question here on SO about memory management that involves NSStrings,
My question is about a school project that I'm working on. It involves mapping
I have a question regarding the best design pattern for code reuse when dealing
My question involves this simple walkthrough shown in the article Preserve Size and Location
This question involves 3 tables and 1 form in my Access database. The tables
I have a question which involves calling a function with 2 parameters of a
I have a question which I think involves conditional entropy in the field of
This is more a general question but my particular case involves a ruby/rails app
This is mostly a data warehouse philosophy question. My project involves an Oracle forms
I'm not sure what to call this question, since it involves a variety of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.