-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.js
37 lines (25 loc) · 869 Bytes
/
controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
let app = angular.module("chatApp", ['firebase']);
app.controller("chatApp", chatApp);
chatApp.$inject = ['$scope', '$location', '$log'];
function chatApp($scope) {
let myDataRef = new Firebase("https://chatapp-d3f5f.firebaseio.com");
let urlParams = new URLSearchParams(window.location.search);
$scope.userName = urlParams.get('name');
$scope.appName = "ChatApp";
$scope.submit = function () {
let m = $('#msgIpt').val();
myDataRef.push({
name: $scope.userName,
text: m
});
$('#msgIpt').val('');
};
myDataRef.on('child_added', function (snapshot) {
let msg = snapshot.val();
displayMsg(msg.name, msg.text);
});
function displayMsg(name, text) {
$('<div />').text(text).prepend($('<em/>').text(name + ': ')).appendTo('#msgList');
$('#msgList')[0].scrollTop = $('#msgList')[0].scrollHeight;
}
}