Skip to content

Instantly share code, notes, and snippets.

@codepreneur
Created June 28, 2014 23:36
Show Gist options
  • Save codepreneur/45af9d0d40a29c47ffd6 to your computer and use it in GitHub Desktop.
Save codepreneur/45af9d0d40a29c47ffd6 to your computer and use it in GitHub Desktop.
Angular + Firebase = <3
<html ng-app="myapp">
<head>
</head>
<body ng-controller="MyController">
<div id="messagesDiv">
<div ng-repeat="msg in messages"><em>{{msg.from}}</em>: {{msg.body}}</div>
</div>
<input type="text" ng-model="name" placeholder="Name">
<input type="text" ng-model="msg" ng-keydown="addMessage($event)" placeholder="Message...">
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.6/angular.min.js'></script>
<script src='https://cdn.firebase.com/js/client/1.0.17/firebase.js'></script>
<script src='https://cdn.firebase.com/libs/angularfire/0.7.1/angularfire.min.js'></script>
<script>
var app = angular.module("myapp", ["firebase"]);
function MyController($scope, $firebase) {
var ref = new Firebase("https://makers.firebaseio.com/");
$scope.messages = $firebase(ref);
$scope.addMessage = function(e) {
if (e.keyCode != 13) return;
$scope.messages.$add({from: $scope.name, body: $scope.msg});
$scope.msg = "";
};
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment