Can anyone give me some advice on the pros / cons of using events heavily to keep different parts of an Angular app in sync with each other?
I am considering using a series of events and event listeners to wire together an SPA with multiple concurrent and nested views, provided by Angular's ui-router. The layout of the SPA could be analogous to gmail, where there are logically separate regions of the screen (left area with list of mail folders, top navbar, main details view, etc).
I have been looking at ways to keep all the controllers in sync with regards to models they all need to access at the same time. When a model is updated by the top view, if some of that model is displayed in the main view, I want the main view to notice the change, and update its view accordingly.
I use services to share models across controllers, as is considered the best practice, but there are issues with that approach as discussed in depth in this question.
A possible solution to this is to use Angular's
I've answered one of the questions you linked: here So that might help you.
Which might also answer the question in your comment.
Also my advice is to not abandon OO. But embrace it, angular will then reward you by working all of the time.
Had you in the previosly linked question Had a
User object with a password field you would have never had the issue Because the password would always have been reference-able through the user. And all of the bindings to
User.password would have worked.
So only ever have one source of data. Keep that reference. And your two way binding will modify that data. You shouldn't have to worry about propagating it throughout your app in events.