Skip to content
Brett Cassette edited this page Aug 23, 2014 · 4 revisions

How do you create, update, and destroy data? These methods all begin with a $, meaning they are mutating.

$save

Save is the simplest to use persistence method because it is the most flexible. Whether you're creating or updating an instance, calling $save will get the job done:

var post = Post.new({title: "Great post!"});
post.$save();

Save calls the createURL or updateURL on your model depending on which action is necessary.

Or in your view:

<form ng-submit="post.$save()">
  <input ng-model="post.title">
</form>

$create

When you're creating a new instance, and want to save it immediately, use $create:

var post = Post.$create({title: "Great post!"});

Create calls the createURL on your model.

$update

If you have an instance with changes, call $update:

<form ng-submit="post.$update()"></form>

Update calls the updateURL on your model.

$delete

When you need to destroy data, call $delete:

<button ng-click="post.$delete()">

Delete calls the deleteURL on your model.

Where to next? How about Pagination?