I am trying to allow the customer to edit a list of items by using ngRepeat and ngModel. But i am not able to set response to the input fields Here is the code.
<form name="customerupdateForm" ng-submit="EditCustomerSubmit(updatecustomer)" class="horizontal-form">
<div class="row-fluid" ng-repeat="updatecustomer in itemList">
<div class="control-group">
<label class="control-label">Customer Name</label>
<input type="text" name="customer_name" ng-model="updatecustomer.customer_name" class="span6 m-wrap"/>
</div>
<!--/span-->
<div class="control-group">
<label class="control-label">Company Name</label>
<input type="text" name="company_name" ng-model="updatecustomer.company_name" class="span6 m-wrap"/>
</div>
</div>
</form>
Angular.js
$scope.id = $routeParams.id;
$scope.getupdateCustomerdata = function(id){
$http({
method: 'get',
url: 'api/master/customer/getupdatecustomer?id=' + $routeParams.id
}).then(function successCallback(response) {
console.log(response.data['customer_name']);
$scope.updatecustomer = {};
//set response to input filed
$scope.updatecustomer.customer_name = response.data['customer_name'];
});
}
$scope.getupdateCustomerdata();
I am assuming that your api is returning you a list of Customers
, in that case you have to make the api response equal to itemList
in angularjs
.then(function successCallback(response) {
console.log(response.data['customer_name']);
$scope.updatecustomer = {};
//set response to input filed
$scope.itemList = response;
});
if your response is a list of objects and has properties named customer_name
, company_name
then your input elements will be populated with the model value