2016-06-23 194 views
0

我是新的使用Restangular,我不明白如何解決承諾使用我自己的服務。我一直試圖返回customGET方法,但在我的控制器響應它是一個包含所有restangular資源的方法的對象,所以我不明白如何獲得響應數據。我檢查網絡活動及其檢索的數據。如何解決Restangular資源

我的服務

angular 
    .module('Form29') 
    .service('Form29Service', Service); 

    Service.$inject = ['Restangular']; 

    function Service(Restangular) { 

    this.serviceResource = Restangular.all('forms'); 
    this.getForm29 = getForm29; 

    function getForm29(_month, _year, _type) { 
     var params = { 
     rut: '76195496', 
     month: _month, 
     year: _year, 
     type: _type 
     }; 
     return this.serviceResource.customGET('',params); 
    } 
    } 

我的控制器

angular 
    .module('Form29') 
    .controller('Form29Controller', Controller); 

    Controller.$inject = ['Form29Service']; 

    function Controller(Form29Service) { 

    var vm = this; 

    vm.submitForm = submitForm; 

    function submitForm(month, year, type){ 
     Form29Service.getForm29(month, year, type).then(showForm); 
    } 
    function showForm(response){ 
     console.log(response); 
    } 

    } 
+1

你是否嘗試替換返回this.serviceResource.customGET('',params);通過this.serviceResource.get(params) – Silvinus

回答

1

我認爲這個問題是您嘗試讓customGet空路徑,在這種情況下,您可以輕鬆地做簡單​​3210將返回承諾爲你。