范围未定义为文本框

问题描述 投票:0回答:1

我正在尝试按照下面的代码将值绑定到文本框。但是无法这样做并且在调试期间将msg作为Scope未定义,并且在开发人员工具中没有错误信息。

$ scope.onItemSelected中的问题,实际上我是来自api的响应(数据)。看起来只是范围的问题,但无法找到并尝试以不同的方式绑定文本框。

<!DOCTYPE html>
<html>
<head> 
    <script src="Scripts/angular.js"></script>
    <script src="Scripts/angular-resource.js"></script>
    <script>
        var IM_Mod_app = angular.module('IM_ng_app', []);   
        IM_Mod_app.controller("IM_Ctrl", function ($scope, $http) {              
              $http({
                method: 'GET',                    url: 'http://localhost:55758/api/Maintenance/GetFilteredItems',
                params: { Brand_Id: 'BR', Vt_Id: 'B' }
            }).then(function successCallback(response) {                
                $scope.items = response.data;
            }, function errorCallback(response) {
                                });    

            // on Item Selected - To fetch  Item details.
            $scope.onItemSelected = function () {                   
                $http({
                    method: 'GET',
                    url: 'http://localhost:55758/api/Maintenance/GetItem',
                    params: {  Brand_Id: 'BR', Item_Id : '12345' }
                }).then(function successCallback(response) {
                    alert(response.data); // Got data from the API with out any issues.
                    //$scope.itemDetails = response.data; -----> msg : itemDetails undefined.
                    //alert(itemDetails);
                    debugger;
                    $scope.itemid = response.data.ITEM_ID;  ----->msg : itemid undefined.
                    alert(response.data.ITEM_ID);
                    $scope.itemname = response.data.ITEM_NAME; ----->msg : itemname undefined.
                    alert(response.data.ITEM_NAME);
                    //$scope.NET_WEIGHT = itemDetails.NET_WEIGHT; ----->msg : itemDetails undefined.
                }, function errorCallback(response) {

                });
            }
        });


    </script>


</head>

<body ng-app="IM_ng_app">
    <table ng-controller="IM_Ctrl">
        <tr>
            <td>


                <select ng-model="itm.ITEM_NAME" multiple="true" size="15" ng-options="itm.ITEM_ID for itm in items" ng-change="onItemSelected(itm)"></select>
                <h2>  {{itm.ITEM_ID}}  </h2>

            </td>   
            <td>
                <div>

                    <input type="text" id="inpItemId" name="nameItemId" ng-trim="false" ng-value="itemid" />
                </div>
                <div>

                    <input type="text" id="inpItemName" name="nameItemName"  ng-model="itemname" />
            // <input type="text" id="inpItemName" name="nameItemName" value="{{itemname}}" />
                </div>
                <div>                   
                    <input type="text" class="form-control" id="NET_WEIGHT" ng-model="itemDetails.NET_WEIGHT" />
                </div>


            </td>
        </tr>

    </table>

</body>
</html>

有人可以帮助我吗?

angularjs angularjs-scope angularjs-select angularjs-bindings
1个回答
0
投票

这可能有所帮助

HTML

<input type="text" ng-model="itemobj.iiemValue">

调节器

$scope.itemobj = {} //defined empty object
© www.soinside.com 2019 - 2024. All rights reserved.