Thanks for the reply, 

You're 100% right, I had thought that every time I changed page another 
callback was being added and my function comparison was failing which is 
why I switched to toString(). 

What actually was happening is I had several instances of the controller on 
different pages and each different controller declaration was being treated 
as a separate callback, which is the desired behaviour but looked like a 
bug when I thought the controller only had a single instance

On Saturday, May 17, 2014 1:39:43 PM UTC+1, steven smock wrote:
>
> Liam,
>
> I am not sure that you need to toString() your functions.  If you want to 
> prevent duplication in your arrays, can you not just use 
> thingInMyArray.indexOf(newFunction) == -1?
>
> But then, your head-scratcher sounds like it might be encouraging its own 
> itch.  Can you say a little more about what you are trying to accomplish?
>
> Best,
> SS
>
> On Friday, May 16, 2014 11:47:17 AM UTC-4, Liam Ryan wrote:
>>
>> I have a bit of a head-scratcher. 
>>
>> I'm trying to implement an observer service to provide $scope.$watch 
>> functionality to services.
>>
>> I add a callback function to an object : function[] map based on the 
>> following logic, assuming newCallbackFunction  is the callback I'm trying 
>> to add
>>
>>
>> angular.forEach( thingInMyArray, function( existingFunction ) {
>>     if newCallBackFunction.toString() === existingFunction.toString() {
>>       //don't add
>>    }
>> }) 
>>
>> I want to ensure that if I have two controllers with the same update 
>> method that they will both be notified, not just the function that was in 
>> the array first. Any suggestions?
>>
>

-- 
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