我正在尝试按照以下代码将值绑定到文本框。但是无法这样做,并且在调试期间将 msg 作为 Scope undefined 并且在开发人员工具中没有错误 msg。
$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>
有人可以在这里帮助我。