angularjs - Creating an Angular API Service to provide access to all Web APIs -
angularjs - Creating an Angular API Service to provide access to all Web APIs -
i want create angular service allow me access number of $resources, each access given api. example, want of api calls generated single service using syntax like
var   info = api.products.query(function() {   $scope.products = data.products;  });    or
var   info = api.customers.get({id:123}, function() {   $scope.customer = data;  });    where products , customers angular $resources reside within api service. trying this
    var app = angular.module('myapp', ['ngroute', 'ngsanitize', 'ngresource', 'api']);       var apiservice = angular.module("api", ["ngresource", function ($resource) {                   this.products = $resource('/webapi/products/:type/:id', {id:'all'},                 {                     systemupdate: { method: 'get' },                 });                  this.customers = $resource('/webapi/customers/:type/:id', {id:'all'},                 {                     systemupdate: { method: 'get' },                 });              }]);    but getting error during compilation of service. uncaught error , when @ same page in firefox, error not give more detail going wrong.  right way give kind of functionality?
here mill now:
    app.factory("api", ["ngresource", function ($resource) {            homecoming {             api: {                 alerts: $resource('/webapi/alert/:type/:id', { id: 'all' },                  {                      systemupdate: { method: 'get' },                      autoarchive: { method: 'post', url: '/webapi/alert/template/:type' }                  })             }         }       }]);       
just create mill , homecoming necessary resources:
var app = angular.module("myapp"); app.factory("api", ["$resource", function($resource) {      homecoming {         api: {             customers: $resource('/webapi/customers/:type/:id', {id:'all'},             {                 systemupdate: { method: 'get' },             });         }     } }]);    inject when needed:
app.controller("mycontroller", ["api", function(api) {     api.customers.get({}, function(data) {         //sample  phone call customers     }); }]);        angularjs 
 
Comments
Post a Comment