Data sharing among angularJS

53 Views Asked by At

I am new to angularJS, I still confused about data sharing among angularjs( between controllers, directives,factorys etc) Seems like there are many ways to let them talk to each others. such as $rootScope, $emit broadcast, using sevice require or isolate scope. I was once told that using factory is the best and safest way to do so. I am confused that why way is best in practice?

1

There are 1 best solutions below

0
On BEST ANSWER

$rootScope is for special cases, should not be generally used.
To share code between controllers use services (factories, for example).
Directives can directly share data with templates scope.

Perhaps I was not exhaustive, but it's a start... :-)

I add, as an advice: before trying to understand how to let components communicate, try to better understand the components themselves, what they are, and what they do. Then, you can ask how they communicate... :-)