Advertisement
joelmello

Angular 1.4 Service Example

Dec 2nd, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// <reference path="../../../Gruntfile.js" />
  2.  
  3. 'use strict';
  4.  
  5. angular.module('exmapleApp')
  6.     .factory('WithdrawalService', function (appConstants, $http) {
  7.         var service = {
  8.             getAllWithdrawals: function (successHandler) {
  9.                 //returns all withdrawal history for currently logged in user
  10.                 return $http.get(appConstants.api.url + '/withdrawals/getwithdrawals')
  11.                 .success(function (res) { successHandler(res); });
  12.             },
  13.             postWithdrawal: function (data, fnSuccess, fnError) {
  14.                 return $http.post(appConstants.api.url + '/withdrawals/withdraw', {
  15.                     amount: data.amount,
  16.                     fullName: data.fullName,
  17.                     phoneNumber: data.phoneNumber,
  18.                     paymentMethod: data.paymentMethod,
  19.                     paypalEmail: data.paypalEmail,
  20.                     mailingAddress: {
  21.                         AddressLine1: data.mailingAddress.AddressLine1,
  22.                         AddressLine2: data.mailingAddress.AddressLine2,
  23.                         City: data.mailingAddress.City,
  24.                         State: data.mailingAddress.State,
  25.                         PostalCode: data.mailingAddress.PostalCode,
  26.                         Country: data.mailingAddress.Country,
  27.                     }
  28.                 })
  29.                 .success(function (res) {
  30.                     fnSuccess(res);
  31.                 }).error(function (err) {
  32.                     fnError(err);
  33.                 });
  34.             }
  35.         };
  36.  
  37.         return service;
  38.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement