问题
First of all, I have read so much info you all share about communication between controllers, that I'm now so confused about the BEST way to do it. I understand I should use service, but don't really know what it means from the examples you all wrote.
Here is my scenario: Left side of my page I have a side bar with a simple folder/files tree. I have used angular Tree Component and it works great for me: http://jimliu.github.io/angular-ui-tree/
On the right side of the page, I have a view that is being changed by user navigation. Each time user select any node on the tree, I want to be able to tell any right side page controller which node has been selected. Each selection on tree should notify any one who want to listen to that change.
I don't like the idea of using $rootScope and fire event from the service, Is that the only way?
回答1:
To illustrate how it can be done, I created some example code using a service to share data between Controllers and Directives:
app.factory('SharedService', function() {
return {
sharedObject: {
value: ''
}
};
});
http://plnkr.co/edit/Q1VdKJP2tpvqqJL1LF6m?p=preview
Hope that helps
来源:https://stackoverflow.com/questions/25349845/how-to-communicate-between-directive-tree-component-and-any-other-controller-o