Hi Harila,

Actually is extremely inadvisable, is simple, quick but ugly as fuck, you
start putting everything inside the $rootScope and you lost control, for
sure Sander can explain more about the disvantages, I'm too limited... I
really recommend using services... I know that is kinda scary when you
start using another structures but its very simple, your service will
return an object... and that object is the same no matter how many times
you inject the service into controllers or another services.

Cheers ;)

On Wed, Mar 30, 2016 at 4:30 PM, <[email protected]> wrote:

> Thanks Sander
>
>
> On Tuesday, March 29, 2016 at 12:32:17 PM UTC+2, Sander Elias wrote:
>>
>> Hi Pablo, Harila...,
>>
>> Pablo, your advice to move it to a service is a spot on. The events might
>> be a bit overkill, if you just want to monitor the length of an array.
>>
>> Something like this will work:
>>
>> app.service('mySpecialList', function(){
>>   return {list: []}
>> })
>>
>> app.controller('ctrl1', function($scope, mySpecialList){
>>     $scope.myList = mySpecialList
>>     $scope.watch(function () {return $scope.myList.length}, function () {
>>         // handle length mutation in here
>>     })
>> })
>>
>> app.controller('ctrl2', function($scope, mySpecialList){
>>     $scope.myList = mySpecialList
>>     $scope.watch(function () {return $scope.myList.length}, function () {
>>         // handle length mutation in here
>>     })
>> })
>>
>>
>>
>> This works, because in JS an array is always passed by reference. This
>> means that every controller will see the exact same array.
>>
>> Hope this helps a bit,
>> Regards
>> Sander
>>
> --
> 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 https://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to