I am writing a line-of-business application in Angular, and I have come across a scenario I can't quite find a nice solution to.
I want to show a banner stating that a user has unsaved changes, and that he can save them. So in my index.html, I have the following markup (using bootstrap):
<div class="alert alert-info" role="alert" style="margin: 20px;">
<button class="btn btn-info" ng-click="<CurrentController.Save()>" ng-show="<HasChanges>">Save</button>
<span>You have unsaved changes. Use the button here to save them.</span>
</div>
Now, I have a controller for my current view, and a global appController.
Using prototypical inheritance, my controllers contain functionality to track changes a user makes, and is able to perform whatever actions are necessary to achieve my desired functionality.
My question is:
Since my rootScope does not know about the child controllers, what do I need to do to be able to bind ng-click and ng-show in my above code. In other words, how will index.html know about the currently active controller?
I thought about broadcast
/emit
, but somehow that just doesn't seem pure to me. I also though about having the child controllers 'register' themselves with the $rootScope, but that could cause my to save in old controllers if I introduce errors.
What is the best practice for this? Is there something fundamentally wrong with my design?