Coder Social home page Coder Social logo

angular-dpd's Introduction

angular-dpd

A plugin for Angular that allows for easy interaction with deployd. Usage is the same as the default dpd.js file, but requires configuration of the necessary collections. Extra 'save' helper function added that will POST if the object has no 'id' and will put if it does.

Example usage

var app = angular.module('myApp',['dpd']);

// Configuration:
app.value('dpdConfig',['categories']);
// or
app.value('dpdConfig', { 
  collections: ['categories'], 
  serverRoot: 'http://someotherserver.com/', // optional, defaults to same server
  socketOptions: { reconnectionDelayMax: 3000 }, // optional socket io additional configuration
  useSocketIo: true // optional, defaults to false,
  useBearerAuth: true // optional, sets whether to use HTTP request header auth instead of cookies, defaults to false

});


app.controller('bodyController',function($scope, dpd){

  dpd.categories.get().then(function(data) { }).catch(function(error) { });
	
  dpd.categories.get('414b9c5cc315485d').then(function(data) { }).catch(function(error) { });
	
  // Example with an [advanced query](http://docs.deployd.com/docs/collections/reference/querying-collections.md#s-Advanced%20Queries-2035):
  dpd.categories.get($sort: {name: 1}, $limit: 10, rightsLevel: {$gt:0}}.then(function(data) { });
	
  // Promises are supported:
  dpd.categories.post({"value":"cat1","typeId":"987ad2e6d2bdaa9d"})
  .success(function (result) {
    // use result
  })
  .error(function (err) {
    // on error
  });
	
  dpd.categories.put('414b9c5cc315485d',{"value":"cat123"}).success(function(category){ }).error(function(error) { });
	
  dpd.categories.del('414b9c5cc315485d').success(function(category){ });
  
  // login a user
  dpd.users.exec('login', { username: 'user', password: 'pass' }).success(function(session) { }).error(function(err) { });
});

Socket.IO

If socket.io is enabled in the configuration, it can be used like this:

app.controller('bodyController',function($scope, dpd){
	dpd.categories.on($scope, "changed", function (result) { // this handles "categories:changed"
		console.log("event fired");
	}
	// or
	dpd.on($scope, "categories:changed", function (result) {
		console.log("event fired");
	}
}

For low-level access, the raw socket is exposed as dpd.socket.rawSocket.

Note: We inject $scope in the call so that the library can automatically remove the events if the $scope is $destroyed (such as when a route change occurs).

angular-dpd's People

Contributors

andreialecu avatar slively avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

fotoflo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.