{"size": 869, "ext": "js", "max_stars_repo_path": "controller.js", "max_stars_repo_name": "ZainMohsin/chatApp", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "controller.js", "max_issues_repo_name": "ZainMohsin/chatApp", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "controller.js", "max_forks_repo_name": "ZainMohsin/chatApp", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.4864864865, "max_line_length": 87, "alphanum_fraction": 0.6006904488}
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;
  }




}