如何将ng-click项目传递给http的数据有效负载

时间:2017-04-24 23:01:17

标签: javascript angularjs

我无法将onSMSHeaderDetail_Click中存储的项目传递给http数据有效负载。

ng-click

4 个答案:

答案 0 :(得分:1)

更改此行$scope.threadi = $scope.item;

$scope.threadi = item;

答案 1 :(得分:1)

您可以尝试更改

$scope.threadi = item;$scope.smsDetails= response.data。并把 你的ng-click中的ajax

  $scope.onSMSHeaderDetail_Click = function(item){
        console.log(item);
        $scope.threadi = item;
        // console.log(thread);
 $http({
        url: "http://****",
        dataType: "json",
        method: "POST",
        headers: {
            "Content-Type": "application/json"
        },
        data : {
             phoneId : "******",
             **threadId: $scope.threadi**
        }
    }).then(function (response) {

        $scope.smsDetails= response.data;
    };

答案 2 :(得分:0)

请尝试以下代码

.controller('smsDCtrl',function($ scope,$ http){

$scope.onSMSHeaderDetail_Click = function(item){
$http({
    url: "http://****",
    dataType: "json",
    method: "POST",
    headers: {
        "Content-Type": "application/json"
    },
    data :JSON.strigify( {
         phoneId : "******",
         threadId: item })
}).then(function (response) {
    $scope.smsDetails= response.data.body;}

};

答案 3 :(得分:0)

javascript文件

var ipv=" ///required ip ";
var phoneId = null;
var threadDetailId = null;

.controller(' smsCtrl',function($ scope,$ http){

    $scope.onSMSHeaderDetail_Click = function (item) {
        console.log(item);
        threadDetailId = item;
    };
    $http({
        url: "http://"+ipv+"/getSMSHeaders",
        dataType: "json",
        method: "POST",
        headers: {
            "Content-Type": "application/json"
        },
        data: {
            phoneId: phoneId,

        }
    }).then(function mySucces(response) {

        if(response.data.body==null ||response.data.body =="")
        {
            $scope.myErrorMsgd="No data available";
        }
        else {
            $scope.smsHeaders = response.data.body;
        }
    },function myError(response) {
             $scope.HeaderError="Error: Request failed";
});


$scope.onRefresh= function(){
    $http({
        url: "http://"+ipv+"/updateSMSHeaders",
        dataType: "json",
        method: "POST",
        headers: {
            "Content-Type": "application/json"
        },
        data: {
            phoneId: phoneId,


        }