bhavanpatel

REST SERVICE JS file

May 12th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**********************************************************************************/
  2. /*How to create SERIVCE*/
  3. app.service('rest', function($http) {
  4.     return {
  5.         baseUrl: 'http://ec2-52-36-75-20.us-west-2.compute.amazonaws.com:3000/',
  6.         path: undefined,
  7.         login: function(loginData) {
  8.             var url = this.baseUrl + this.path;
  9.             return $http.post(url, loginData);
  10.         }
  11.     };
  12.  
  13. });
  14.  
  15. /**********************************************************************************/
  16.  
  17.  
  18. /**********************************************************************************/
  19. /* How to call rest Service from Controller*/
  20.  
  21. //Call Service
  22. app.controller('loginCtrl', function($scope, $state, rest) {
  23.     $scope.user = {
  24.         'email': '',
  25.         'password': ''
  26.     };
  27.     $scope.login = function() {
  28.         rest.path = 'login';
  29.         rest.login($scope.user).success(function(responseLoginData) {
  30.             console.log(responseLoginData);
  31.         });
  32.     }
  33. });
  34. /**********************************************************************************/
Add Comment
Please, Sign In to add comment