For a dashboard type project (one page, multiple smaller views of different models) we are using among other tools the Angular framework.
The problem consists of the following:
- I have a controller, which is responsible for retrieving workitem data. For now the workitem data consists of bugamount and backlogitems.
- I have 2 functions in this controller responsible for updating the scope variables (bugAmount and backLogItems)
- I have 2 html files which serve as views. These are included in out main dashboard.html (at basically a random place).
The problem I have now is that the views don't share a common ancestor which has the controller directive which links to the workItemController. I could do that and it would work perfectly, however this seriously reduces the layout possibilities.
Basically the problem: Each view now has the ng-controller attribute because they both need access to the scope. This doesn't work and only one of the views gets updated.
For reference these two divs should be able to be locatd anywhere on the page, and should have access to their shared data (which the ontroller supplies)
<div class="backLogView" ng-controller="WorkItemsController">
...
<tr data-ng-repeat="b in backLogItems">
<td class="text-left">{{b.title}}</td>
<td class="text-left">{{b.status}}</td>
<td class="text-left">{{b.assignedTo}}</td>
</tr>
...
</div>
<div class="bugAmountView" ng-controller="WorkItemsController">
...
{{BugAmount}}
...
</div>
So far I've considered:
- Creating a mutual parent where the ng-controller directive is used, instead of in the separate views. This is an option but will severely reduce the placement of the views (which as far as I'm concerned is a big no-no)
- Using the $rootscope for the controller, for issuance update the current scope to $rootscope.workitems.. This will probably work but means that every controller can reach every other controllers data. Seems to me that can't be right either
Is there a good way to still have the linked functionality in one controller (as it should) but display the views for it's data (bugamount and backlog) in the webpage where they don't have a common ancestor.