2014-04-18 22 views
1

我有這兩個功能:

var getConfigs = function() { 
     var defer = $q.defer(); 
     $http.get('/api/Config/Get') 
      .success(function (data) { 
       defer.resolve({ 
        configs: data, 
       }); 
      }); 
     return defer.promise; 
    } 

    var putConfigs = function(config) { 
     // When I check here I see config has some values 
     $http.put('/api/Config/Put', config); 
    } 

當我打電話getConfigs()我看到對面的提琴手數據來和$ scope.configs填充。但是,當我撥打putConfigs($scope.config);時,我沒有看到任何提琴手,也沒有消息傳到我的主控制器。

有沒有人有任何想法可能是錯的。除了使用Chrome來瀏覽代碼和提琴手以觀察發生的事情之外,還有另一種方式可以調試發生的情況嗎?

回答

1

如果這是你的代碼的程度,那麼你沒有完成$ http循環。你需要處理這個迴應。

var myPut = $http.put('/api/config/put', config); 
myPut.then(function(data){ 
    //things that should happen when the call is successful go here 
}, function(data){ 
    //things that should happen when the call is not successfful go here 
}); 

如果您正在處理響應,您需要在任何人都可以幫助您之前發佈該代碼。