I do have a service. Its called DataFactory.

I just found that you can achieve the same results with out using a factory 
and calling the factory in each controller.

The way I have my app setup I am getting the current users data in a 
MainController which I set on the body tag so EVERY single page and 
controller instantiated with that route will have MainController as a 
parent.

I could then load the data using $timeout OR as you mentioned just use a 
service. Using a service means I call my DataFactory in every single 
controller that I need that data which although it seems like thats the 
point of services and dependency injection, it causes multiple calls of the 
same code. Whereas with a simple timeout I can just grab the data that is 
already there in the parent controller.

I am using the service/ factory method for sure, but I just wanted to know 
if its bad practice to do it the other way

On Thursday, May 1, 2014 4:06:43 PM UTC-4, Chris Rhoden wrote:
>
> The 0 isn't necessary, and using $timeout to defer some action isn't an 
> antipattern, but the rest of your message concerns me. If you're 
> communicating between controllers using $scope, you're doing it wrong. Make 
> a service if two controllers need to share state.
>
>
> On Thu, May 1, 2014 at 4:04 PM, Billy Figueroa <[email protected]<javascript:>
> > wrote:
>
>> Is is bad practice to use $timeout with a time of 0?
>>
>> i.e. 
>> $timeout(function() {
>>    // some action here
>> }, 0);
>>
>> I find that sometimes data doesn't load in a child controller and I may 
>> want to use this. I have avoided using it, but what are peoples experience 
>> with this?
>>
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "AngularJS" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/angular.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> chrisrhoden 
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to