I have a chat page where messages are displayed through ng-repeat
on the array $scope.messages
I am subscribed to a backend-as-a-service and use their api for sending instant messages. When a message is received, the onChatMessage
is executed.
What I'd like to do is to push any messages received to the the $scope.messages
array so that the chat page displays the newly received message. However I don't know how to access the $scope.messages
array from my function. Is this possible?
my controller:
.controller('ChatCtrl',function($scope,$stateParams,$ionicScrollDelegate,$q,principal){
$scope.messages = ["test message 1","test message2];
})
This function calls when a message is received:
function onChatMessage(senderID,message){
// senderID, message are predefined by the api of my backend-as-a-service
// I'd like to push the message received here to scope.messages
// but accessing $scope here leads to undefined error.
}