angular-nested-resource

This is an Angular module which helps with RESTful data
Homepage:
1 person uses it
Author: 638fa0a11d0cb897a6dab71bfdcacf49?d=https%3a%2f%2fidenticons.github.com%2f0b618583b72dfe59b3ee149fd0405b93 roypeled

angular-nested-resource

A lightweight angular module that helps working with RESTful models. I was researching restangular and didn't like the fact that it was dependant on lodash and the dact that the models weren't configurable.

I liked ng-resources approach, but the implementation is horrible with nested objects.

So here is my solution.

Usage

To use this module you must add the JS file to your HTML and add ngNestedResource as a dependency to your app: ```html <!DOCTYPE html> ...

Basic root object

Nested resource is using angular's own resource module as a scaffolding. So you can use the original resource configuration: ```js

var organizations = nestedResource("/api/organizations/", { getAll: {method: "GET", isArray: true}, create: {method: "POST"} });

organizations.getAll(); // GET: "/api/organizations/" organizations.create({name: "Google.com"}); // POST: "/api/organizations/", payload: "{name: 'Google.com'}" // returns { id:1, name: "Google.com"}

When specifying a route to an action you can add a wildcard (@) which will be replaced with the parameter supplied to the action.

Extending a nested object

You can nest objects using the 'nested' property, and just follow the same pattern inside.

Async Handling

Since this module is using resource, all requests are handled with $q's promises.

comments powered by Disqus
This page was last updated almost 4 years ago.