This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This will return a promise of an Array | |
var promisedArray = $q.when([1,2,3]); | |
//Normal way of getting length in angular | |
promisedArray.then(function(arr) { | |
var length = arr.length; | |
// Do something with length in callback | |
}) | |
//Using promises transformation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module("test").service("Greeting", function() { | |
this.greet = null; | |
this.greetTo = function(name) { | |
this.greet = "Hello " + name; | |
} | |
}); | |
angular.module("test").controller("TestCtrl", function(Greeting) { | |
$scope.greeting = Greeting; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.config(function(RestangularProvider) { | |
// First let's set listTypeIsArray to false, as we have the array wrapped in some other object. | |
RestangularProvider.setListTypeIsArray(false); | |
// Now let's configure the response extractor for each request | |
RestangularProvider.setResponseExtractor(function(response, operation, what, url) { | |
var newResponse; | |
// This is a get for a list | |
if (operation === "getList") { | |
// First the newResponse will be response.objects which is actually an array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Use LATEST folder to always get the latest version--> | |
<script type="text/javascript" src="http://cdn.jsdelivr.net/restangular/latest/restangular.js"></script> | |
<script type="text/javascript" src="http://cdn.jsdelivr.net/restangular/latest/restangular.min.js"></script> | |
<!-- Or use TAG number for specific version --> | |
<script type="text/javascript" src="http://cdn.jsdelivr.net/restangular/0.5.3/restangular.js"></script> | |
<script type="text/javascript" src="http://cdn.jsdelivr.net/restangular/0.5.3/restangular.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var restangualrSpaces = Restangular.one("accounts",123).one("buildings", 456).all("spaces"); | |
// This will do ONE get to /accounts/123/buildings/456/spaces | |
restangularSpaces.getList() | |
// This will do ONE get to /accounts/123/buildings/456/spaces/789 | |
Restangular.one("accounts", 123).one("buildings", 456).one("spaces", 789).get() | |
// POST /accounts/123/buildings/456/spaces | |
Restangular.one("accounts", 123).one("buildings", 456).all("spaces").post({name: "New Space"}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//In your app configuration (config method) | |
RestangularProvider.setOnElemRestangularized(function(elem, isCollection, route) { | |
if (!isCollection && route === "buildings") { | |
// This will add a method called evaluate that will do a get to path evaluate with NO default | |
// query params and with some default header | |
// signature is (name, operation, path, params, headers, elementToPost) | |
elem.addRestangularMethod('evaluate', 'get', 'evaluate', undefined, {'myHeader': 'value'}); | |
} | |
return elem; | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//GET /messages/123/archive | |
Restangular.one("messages", 123).customGET("archive") | |
//POST /messages/clear-all?param=param2 with body of {force: true} | |
Restangular.all("messages").customPOST("clear-all", {param: "param2"}, {}, {force: true}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var restangualrSpaces = Restangular.one("accounts",123).one("buildings", 456).all("spaces"); | |
// This will do ONE get to /accounts/123/buildings/456/spaces | |
restangularSpaces.getList() | |
// This will do ONE get to /accounts/123/buildings/456/spaces/789 | |
Restangular.one("accounts", 123).one("buildings", 456).one("spaces", 789).get() | |
// POST /accounts/123/buildings/456/spaces | |
Restangular.one("accounts", 123).one("buildings", 456).all("spaces").post({name: "New Space"}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = function(grunt) { | |
// Project configuration. | |
grunt.initConfig({ | |
dirs: { | |
dest: 'dist' | |
}, | |
bower: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "restangular", | |
"version": "0.5.3", | |
"main": "./dist/restangular.min.js", | |
"description": "Restfull Resources service for AngularJS apps", | |
"repository": { | |
"type": "git", | |
"url": "git://github.com/mgonto/restangular.git" | |
}, | |
"dependencies": { |