2016-05-13 5 views
0

私はwonderJSでこれをどうやって書くことができますか?

requests: { 
    fetchUsers: function() { 
     return { 
      url: 'https://www.example.com/api/v2/users', 
      type: 'GET', 
      username: '[email protected]/token', 
      password: 'myAPItoken' 
     }; 
    } 
} 

答えて

2

これは単なる例です。

あなたのコントローラ:

var userCtrl = angular.module('UserCtrl',[]); 

    userCtrl.controller('UserController',function($scope,Users){ 
     var getUsers = Users.fetchAll(); 
      getUsers.then(function(response){ 
       $scope.users = response; 
      }); 
    }); 

あなたのサービス:

var userSrvc = angular.module('UserSrvc',[]); 

userSrvc.factory("Users",function($http){ 

    return{ 
     fetchAll: function(){ 
      var request = $http({method:'GET', url:'https://www.example.com/api/v2/users'}); 
      return request; 
     } 
    } 
}); 
関連する問題