I am facing a requirement where a single page needs to display a lot of different data, all within one vertical-scrolling page.
To manage this, I have implemented collapsible divs on the page controlled by ng-if
to efficiently handle the DOM elements.
In the initial prototype, I had all the logic for these divs in one controller. However, I have now decided to take a different approach. I want to have one main controller for the entire page and separate child controllers for each collapsible div.
I have created an object for each div in the page controller and added multiple child controllers in my main module (app.js). I expected each of them to be children of the pageCtrl
so that I can access the data for each div from there.
Unfortunately, this setup is not working as expected. There are no errors in the console, but none of the divs are visible.
The structure of my code is as follows:
<body ng-app ="mainModule">
<div ng-controller ="pageCtrl">
<div ng-controller = "collapse1Ctrl" ng-include="collapse1.tpl" ng-if="collapse1reqd">
<div ng-controller = "collapse2Ctrl" ng-include="collapse2.tpl" ng-if="collapse2reqd">
<div ng-controller = "collapse3Ctrl" ng-include="collapse3.tpl" ng-if="collapse3reqd">
<div ng-controller = "collapse4Ctrl" ng-include="collapse4.tpl" ng-if="collapse4reqd">
<div ng-controller = "collapse5Ctrl" ng-include="collapse5.tpl" ng-if="collapse5reqd">
</div>
My JavaScript code looks like this:
angular.module("mainModule", []);
angular.module("mainModule").controller("pageCtrl", pageCtrlFn);
angular.module("mainModule").controller("collaspse1Ctrl", collaspse1CtrlFn);
angular.module("mainModule").controller("collaspse2Ctrl", collaspse2CtrlFn);
angular.module("mainModule").controller("collaspse3Ctrl", collaspse3CtrlFn);
angular.module("mainModule").controller("collaspse4Ctrl", collaspse4CtrlFn);
angular.module("mainModule").controller("collaspse5Ctrl", collaspse5CtrlFn);
I have checked that all templates and conditions are correctly placed.
Due to the length of my code, I am refraining from posting it at the moment. I may create a similar fiddle to share soon.
At this point, I am questioning if there might be an issue with the overall structure of my implementation. Any insights would be greatly appreciated!