0

尝试使用以下代码将数据绑定到范围内的输入控件。

var app = angular.module('ng_app', []);

app.controller("ITEM_Ctrl", function ($scope, $http) {
    var PlantId = "abcFC"; $scope.mdItemId; $scope.mdFlavorId; $scope.itemDtls = {};
    $http({
        method: 'GET',
        url: 'http://localhost:12752/api/Item/GetItem',
        params: { Plant_Id: PlantId, Item_Id: '1234567' }
    }).then(function successCallback(response) {
        debugger;
        //  $scope.itemDtls = {};   
alert(response.data);  --> in alert msg as  [object Object]            
    //    $scope.itemDtls = response.data; -->  ReferenceError: itemDtls is not defined
      //  $scope.testmdItemId = itemDtls.ITEM_ID;
        //  $scope.itemDtls =   response.data;
     //   $scope.mdItemId = response.data.ITEM_ID;  --> scope mdItemId undefined
       // $scope.mdItemId = JSON.parse(response.data.ITEM_ID);
       // $scope.mdFlavorId = JSON.parse(response.data.FLAVOR_ID);
      //.mdFlavorId = "test data";  -- > binding successfully
        $scope.itemDtls = response.data;
            $scope.mdItemId = itemDtls.ITEM_ID;
            $scope.mdFlavorId = response.data.FLAVOR_ID;    
    }, function errorCallback(response) {

    });
});

尝试以不同的方式绑定到上面的输入控件,但将 msg 作为未定义的范围。

<body ng-app="ng_app">
    <table ng-controller="ITEM_Ctrl">
        <tr>              
            <td>
                <div>                   
                    <input type="text" id="itemid"  ng-model="mdItemId" />
                </div>
                <div>                 
                    <input type="text" id="flavorid"  ng-value="mdFlavorId" />
                </div>                
            </td>
        </tr>
    </table>
4

1 回答 1

0

像这样试试。

 var itemDtls  = response.data;
 $scope.mdItemId = itemDtls [0].ITEM_ID;
于 2019-03-12T12:46:35.983 回答