I am facing a challenge in handling intricate nesting of templates (also known as partials) within an AngularJS application.
To illustrate my predicament, I have created an image:
As depicted, this application has the potential to become quite complex with numerous nested models.
This is a single-page application that loads an index.html containing a div element in the DOM with the ng-view
attribute.
Regarding circle 1, there is a Primary navigation that loads relevant templates into the ng-view
. I achieve this by passing $routeParams
to the main app module. Here is a snippet from 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 loaded into the ng-view
contains an additional sub-navigation. This sub-nav must then load templates below it - but given the usage of ng-view, I am unsure of the approach to take.
While I can include additional templates within the initial one, these templates are expected to be quite intricate. I prefer to keep all templates separate to facilitate easier updates and prevent dependencies on parent templates for accessing their children.
In circle 3, complexity increases further. It is possible that sub-navigation templates may have a 2nd sub-navigation requiring its own templates to be loaded into the area indicated in circle 4
How should one structure an AngularJS app to manage such complex nesting of templates while ensuring they remain independent?