R
R
Roman Rakzin2015-07-05 00:55:52
Angular
Roman Rakzin, 2015-07-05 00:55:52

Can't access $rootScope from another controller in angularjs.TypeError: $rootScope.get_groups is not a function?

I create the $rootScope.get_groups() function in one control.
Then I try to call this function from another controller, but it says
TypeError: $rootScope.get_groups is not a function
Why is it not read from $rootScope?
It seems that when the 2nd controller accesses this function, it does not seem to exist yet.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-07-05
Protko @Fesor

it's simple, if you inject a scope into a controller, you're doing something wrong. You need a common functionality - take it out to services. If you limit yourself and allow the use of scope only in the link function of directives, then life will become much more pleasant. $rootScope, for declaring which global shortcuts, in principle, it is permissible to pull, but also somehow not very cool. Usually only for events.

E
Eugene Kubesh, 2015-07-06
@Basters

Declare functions in $rootScope? Yes, you are sick, sir!
gost_9903452_orig_.jpg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question