I have been able to get the behavior that I am looking for in this code but I just wanted to make sure I was heading down the right path. I have read alot about event listeners as well but wasn't able to figure out how to implement that so I was wondering if my code works just as good, better, or worse.
In my service:
.factory('Messages', function($firebaseArray, FBURL, $window) {
var messagesRef = new $window.Firebase(FBURL + '/messages');
return $firebaseArray(messagesRef);
})
.factory('Chatroom', function($firebaseArray, FBURL, $window) {
var chatroomRef = new $window.Firebase(FBURL + '/chatroom');
return $firebaseArray(chatroomRef);
})
Then in my controller:
$scope.messages = Messages;
$scope.chatroom = Chatroom;
$scope.addMessage = function(message) {
$scope.messages.$add({
text: message.text,
userName: message.userName
});
$scope.chatroom.$add({
text: message.text,
userName: message.userName,
});
message.text="";
}
So right now I am adding the text and username to both child nodes on ng-click. If I wanted to add this to more child nodes like profile and whatever else it may be can I just keep putting in the $add that references the different node or is that bad practice? Thank you in advance.