2015-10-27 17 views
1

如何將數據從http.post結果傳遞給IonicPopUp?使用http.post結果數據的IonicPopUp

在我的http.post成功部分內我創建alertPopUp函數傳遞結果作爲參數。

它打開彈出窗口,但沒有要顯示的數據。

我想顯示$ scope.result的任何數據。

下面是代碼我使用的樣品從http://ionicframework.com/docs/api/service/ $ ionicPopup /:當你收到result對象

`$scope.showAlert = function(result) { 

var alertPopup = $ionicPopup.alert({ 

    title: 'Detais', 
    template: 'Details : 1. {{result}} 2. {{state}} {{result.vehicle_brand}} 2. {{scope}}' 
}); 
alertPopup.then(function(res) { 
    console.log('Thank you for not eating my delicious ice cream cone'); 
}); 
};` 

回答

1

這也許是的對象的屬性訪問問題。

從$ http.post成功回調函數中嘗試以下代碼。試着打印出結果的結構類似這樣的片段:

$http.post(url).then(function(result){ 
    console.log(JSON.stringify(result, null, 2)); 
}); 

我認爲它的結構,也許是這樣的:

{ 
    "data": //Your result should be available here! 
     { "vehicle_brand": { "a": "b" } },  
    "status": 200, 
    "config": { 
     "method": "POST", 
     ... 
    } 
    "statusText": "OK" } 
} 

然後你就可以將它傳遞給你的離子彈出功能如下:

$http.post(url).then(function(result){ 
    console.log(JSON.stringify(result, null, 2)); 
    $scope.showAlert(result.data); //Pass the data property as a argument. 
}); 
相關問題