pre {
padding: 20px;
font-size: 16px;
line-height: 20px;
background-color: #fafafa;
border: 1px solid #999;
display: block;
border-radius: 10px;
white-space: pre-wrap;
/* css-3 */
white-space: -moz-pre-wrap;
/* Mozilla, since 1999 */
white-space: -pre-wrap;
/* Opera 4-6 */
white-space: -o-pre-wrap;
/* Opera 7 */
word-wrap: break-word;
/* Internet Explorer 5.5+ */
}
.error {
color: red;
}
JavaScript
// reference to our Firebase instance
var fb = new Firebase('https://kato-sandbox-books.firebaseio-demo.com/book1');
/**
* Our Angular module and controller
*/
var app = angular.module('app', ['firebase']);
app.controller('ctrl', function ($scope, BookFactory) {
// create a synchronized array with a customized version
// of $FirebaseArray
$scope.book = new BookFactory(fb);
// changes the date on a book record, note that we're working
// with Date objects here
$scope.setDate = function(book) {
book.date = new Date();
book.$save();
};
});
/**
* Add a Book factory object which parses dates
*/
app.factory('BookFactory', function ($firebaseObject) {
return $firebaseObject.$extend({
/**
* Called each time there is an update from the server
* to update our Book data
*/
$$updated: function (snap) {
// call the super
var changed = $firebaseObject.prototype
.$$updated.apply(this, arguments);
// manipulate the date
if( changed ) {
this.date = new Date(this.date||0);
}
// inform the sync manager that it changed
return changed;
},
/**
* Used when our book is saved back to the server
* to convert our dates back to JSON
*/
toJSON: function() {
return angular.extend({}, this, {
// revert Date objects to json data
date: this.date? this.date.getTime() : null
});
}
});
});
/*********
RESET DEMO DATA EACH TIME THE PAGE LOADS
*********/
fb.set({
title: "Grapes of Wrath",
author: "John Steinbeck",
date: Date.now() - 3600 * 1000 * 24 * 72 // 72 days ago
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.