I want to trigger a new Chat once the variable newChat
is being changed like this:
$rootScope.newChat = {
roomId: roomId,
friendId: friendId
};
in my ChatController
I $watch
the variable like this:
$rootScope.$watch('newChat', function (data) { /*do stuff*/ }
this works on my page after the first reload of the page without any problems. But for the first load this $watch
gets triggered twice which causes issues on some other parts of the chat.
I checked the value of newChat
. Both times the value is exactly the same. No other parts of my application use the $rootScope.newChat
Variable
Why is that and how can I fix this?