область действия не определена для текстового поля - PullRequest
0 голосов
/ 07 марта 2019

Я пытаюсь привязать значение к текстовому полю, как показано ниже.Но не в состоянии сделать это и получить сообщение об ошибке в виде 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>

Может кто-нибудь помочь мне здесь.

1 Ответ

0 голосов
/ 07 марта 2019

Это может помочь

HTML

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

Контроллер

$scope.itemobj = {} //defined empty object
...