Coder Social home page Coder Social logo

angularjs-pheryjs's Introduction

angularjs-pheryjs

Pretty simple phery.js AJAX service for AngularJS that mimics $resource, for usage with PHP

This depends on phery.js library https://github.com/pocesar/phery

Usage

app = angular.module('App', []);

app.controller('YourController', function($scope, $pheryResource, $timeout){
  far = $pheryResource('your-remote-function');
  
  /* If you want to reach the JSON callback, you need to return PheryResponse::factory()->json($your_data) */
  far['delete']({'id':1}, function(){ /*JSON*/ }, function(){ /*fail*/ }); //calls your-remote-function with DELETE method and id:1
  far.get({'id':1}, function(){ /*JSON*/ }, function(){ /*fail*/ }); // calls your-remote-function with GET method and id:1
  far.post($scope.model, function(){ /*JSON*/ }, function(){ /*fail*/ }); // calls your-remote-function with POST method and post the data from the model
  far.put($scope.model, function(){ /*JSON*/ }, function(){ /*fail*/ }); // calls your-remote-function with PUT method and put the data from the model
  
  far.subscribe({ // subscribe, reach this by returning a PheryResponse::factory()->publish('load') or 'done' for example
    'load': function(data){
      $scope.model = data;
    },
    'done': function(){
      $scope.modal.close();
    }
  });
  
  phery.broadcast('done'); // trigger the subscribed event everythere
  far.publish('done'); // trigger the subscribed event only on this element
  
  far.remote([1,3,4]); // call the remote your-remote-function with any king of arguments directly
  
  far.proxy('div.load'); // proxy this detached element to another DOM element
  
  far.element.on('phery:retry', function(trycount){ // all phery events are available on the element member
    $timeout(function(){
      $scope.message = 'Retrying ' + trycount + '...';
    });
  });
});

angularjs-pheryjs's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

contextworks

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.