I have an AngularJS $resource defined like this:
var Menus = $resource('http://cafe.com/api/menus');
and a RESTful API. So when I do a GET on Menus I get this back:
<cafe>
<collection href="http://cafe.com/api/menus" type="menus">
<template>
<data name="Name" prompt="Menu name" />
</template>
<items>
<item href="http://cafe.com/api/menus/1">
<link href="http://cafe.com/api/menus/1/ingredients" rel="ingredients" />
<data name="Name" prompt="Menu name">Morning</data>
</item>
<item href="http://cafe.com/api/menus/2">
<link href="http://cafe.com/api/menus/2/ingredients" rel="ingredients" />
<data name="Name" prompt="Menu name">Happy Hour</data>
</item>
</items>
</collection>
</cafe>
Question is, how do I delete menu 2? (given that it has its own hypermedia link: http://cafe.com/api/menus/2)
Assuming that you have gone from the XML to an Angular-managed array of JavaScript objects, you can use this to render your objects:
and in your controller you can do this:
Look, no client-side creation of URLs! 🙂
update: fixed a bug in the splice command, was
splice(index, index), but should besplice(index, 1).