2016-02-28 74 views
0

我使用此構建角度庫Generator當我從應用程序調用它們時,庫的所有功能都正常工作,但是使HTTP調用的功能無法正常工作。是否有任何理由阻止從Angular庫調用HTTPS角度庫沒有製作HTTP調用

這裏是庫代碼的代碼示例:

(function (angular) { 

    // Create all modules and define dependencies to make sure they exist 
    // and are loaded in the correct order to satisfy dependency injection 
    // before all nested files are concatenated by Gulp 

    // Config 
    angular.module('myLib.config', []) 
     .value('myLib.config', { 
      debug: true 
     }); 

    // Modules 
    angular.module('myLib.directives', []); 
    angular.module('myLib.services', []); 
    angular.module('myLib', 
     [ 
      'myLib.config', 
      'myLib.directives', 
      'myLib.services' 
     ]); 

})(angular); 

(function (angular) { 
    'use strict'; 
    angular.module('myLib.services', []) 
     .factory('myLib', myLib); 

     myLib.$inject = ['$http', '$rootScope']; 
     function myLib($http, $rootScope) { 

      var myLibrary = {}; 

     myLibrary.register = function() { 
      $http({ 
      method: 'POST', 
      url: 'url', 
      data: {id: '00000000000'}, 
      headers: {'Authorization': 'Basic ' + credentialsEncoded} 
      }); 
     }; 


      return myLibrary; 
     } 
})(angular); 

當我試圖調用寄存器功能HTTP調用不作出然而,調用另一個功能是工作的罰款。

+0

你是否縮小了你的庫? –

+0

你能說清楚你的意思嗎?任何代碼示例? –

+0

是的,但我也試過未縮小版本 – user1920302

回答

0

$http(...)你創建一個所謂的承諾。執行查詢只需撥打

$http({...}).then(function successCallback(response) { 
    // this callback will be called asynchronously 
    // when the response is available 
}, function errorCallback(response) { 
    // called asynchronously if an error occurs 
    // or server returns response with an error status. 
}); 

看到官方Angular $http文檔中有關回調的詳細信息。