Recursion in a factory

682 views
Skip to first unread message

tas pas

unread,
Jan 3, 2013, 12:30:21 PM1/3/13
to ang...@googlegroups.com
Hello, 

I'm creating a factory to help me log in to facebook for the application I'm building.

The problem that I'm facing is that I cannot call a function of the factory from a function of it.
It is better illustrated on 
On line 16.

Essensially what I'm trying to do is: 
  1. When the user is logged on facebook the service broadcasts that and, after setting a $rootScope var, a controller takes care of everyrthing.
  2. When the user is not logged on facebook, the service logs him in (via the FB api) and *tries* to call the login function again so the user can go through the route described above.
I couldn't set the $rootScope var there for some reason I cannot understand. To be thourough on that, the $rootScope var on the service could be set up, but couldn't reach the controller when I broadcasted the same message from the "not logged on facebook" place.

Althought I'm suspecting it is a javascript issue, not an angular specific one, can anyone help me on that?

Thank you 







Peter Bacon Darwin

unread,
Jan 3, 2013, 12:48:35 PM1/3/13
to ang...@googlegroups.com

The factory method is simply called to create your service so 'this' is not relevant here, whether or not you store it as self.

What you need to do instead is simply put the object you are returning in a variable and reference that...

var service = {

  ...
  service.login();
  ···
}
return service;

... sent from my tablet

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
 
 

tas pas

unread,
Jan 4, 2013, 2:20:58 AM1/4/13
to ang...@googlegroups.com
Thanx Peter :)
Reply all
Reply to author
Forward
0 new messages