HTML and CSS Reference
In-Depth Information
This simple example illustrates how to retrieve and save data with Angular's default
CRUD methods (
.get
,
.save
,
.delete
, and
.query
):
// Define CreditCard class
var
CreditCard
=
$resource
(
'/user/:userId/card/:cardId'
,
{
userId
:
123
,
cardId
:
'@id'
},
{
charge
:
{
method
:
'POST'
,
params
:
{
charge
:
true
}}
});
// We can retrieve a collection from the server
var
cards
=
CreditCard
.
query
();
// GET: /user/123/card
// server returns: [ {id:456, number:'1234', name:'Smith'} ];
var
card
=
cards
[
0
];
// each item is an instance of CreditCard
expect
(
card
instanceof
CreditCard
).
toEqual
(
true
);
card
.
name
=
"J. Smith"
;
// non GET methods are mapped onto the instances
card
.
$save
();
// POST: /user/123/card/456 {id:456, number:'1234', name:'J. Smith'}
// server returns: {id:456, number:'1234', name: 'J. Smith'};
For more details see:
Batman
Created by Shopify,
Batman.js
is another framework similar to Knockout and Angular.
It has a nice UI binding system based on HTML attributes and is the only framework
written in coffeescript.
Batman.js
is also tightly integrated with
Node.js
and even goes
to the extent of having its own (optional)
Node.js
server. At this time, its following is still
relatively small on github in comparison to the others (
Figure 4-14
).
Figure 4-14. Batman github stats, June 2012
For a RESTful application that demonstrates Batman's server synchro‐
nization, see the HTML5e
Batman repository
.