Why use $ rootScope to exchange data between controllers when factories can do the same?

I understand that $ rootScope is some kind of global variable that allows it to be shared between controllers. Factories can also do the same. So why not use a factory instead? When should $ rootScope be used and when should factory be used, given that they accomplish almost the same purpose?

+4
source share
3 answers

AngularJS FAQs are pretty good here :

$rootScope ,

Angular, . , , , .

, . $rootScope , . , , , , ng-show, , $scope.

, , $rootScope , () . , , . $rootScope, , , , .

, , .

+4

$rootScope . ( : , , - ), $rootScope.
99% . .

+1

- (factory). $rootScope , , , . $rootScope , ($rootScope.$broadcast), / , .

+1

Source: https://habr.com/ru/post/1621697/


All Articles