JSFiddle - React, Tailwind, and code Playground
by psyne
HTML
<script src="https://cdn.firebase.com/v0/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/0.3.0/angularfire.min.js"></script>
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<div ng-app="notesApp">
<div class="container" ng-controller="NotesCtrl">
<div class="row">
<h1>Notes</h1>
<ul class="note-list col-xs-3 nav nav-pills nav-stacked">
<li ng-repeat="note in notes" ng-class="{active: selectedIndex == $index}"><button ng-click="select($index)">{{ note.title }}</button> <button href="#" ng-click="remove($index)">X</button>
</li>
<li><button ng-click="addNote()">+ Add Note</button>
</li>
</ul>
<div class="note-detail col-xs-9">
<textarea rows="20" style="width:100%" ng-model="notes[selectedIndex].body"></textarea>
</div>
</div>
</div>
<div ng-controller="NotesCtrl" class="row">
<div class="container">
<hr />
<h1>Search Notes</h1>
Filter by Title: <input ng-model="search.title" /><br>
<div ng-repeat="note in notes | filter:search:strict ">
<h3>{{ note.title }}</h3>
<p>{{ note.body }}</p>
</div>
</div>
</div>
</div>
JavaScript
var notesApp = angular.module('notesApp', ['firebase']);
function NotesCtrl($scope, angularFire) {
var fireBaseUrl = new Firebase('https://notes9000.firebaseio.com/notes');
$scope.notes = [];
$scope.select = function (note) {
$scope.selectedIndex = note;
};
$scope.remove = function (note) {
var index = $scope.notes.indexOf(note);
$scope.notes.splice(index, 1);
$scope.selectedIndex = 0;
};
$scope.addNote = function () {
var title = prompt('Note Title');
if (title) {
var note = {
title: title,
body: 'Replace me'
};
$scope.notes.push(note);
$scope.active = note;
$scope.selectedIndex = -1;
}
};
angularFire(fireBaseUrl, $scope, 'notes').then(function () {
$scope.selectedIndex = 0;
});
}