我试图按照下面的代码将值绑定到文本框。但是无法这样做,并且在调试过程中无法将msg作为Scope定义,并且在开发人员工具中没有错误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>
有人可以帮我吗?
答案 0 :(得分:0)
这可能有帮助
HTML
%date()
控制器
<input type="text" ng-model="itemobj.iiemValue">