I'm seeing some very odd behaviour in my AngularJS app.
When a single $broadcast is made, the (only) receiver is fired twice.
The effect on the whole app is as if the receiver was only fired once. (i.e. only one of the item is added to the basket).
If you fire the $broadcast twice (i.e. click twice on the button which fires the $broadcast), you get four executions of the receiver, but a quantity of two items are correctly added to the basket.
Is there some spreadsheet-like recalculation going on here? Do $scope functions need to not affect 'plain' javascript variables?
My problem is that I've added an alert and it is being shown twice.
I've done some more work in debugging this:
I added a counter which counted the number of times the broadcast was received.
If the scope (without a dollar) is global, I get the doubled result. If its scope is local to the Ctlr function, I get a non-doubled result.
Could I have somehow created two instances of my controller?
I can see from firebug that $http ajax requests done from the controller only occur once, so I am very confused.