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.

Reply via email to