1

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();
4
  • What exactly is the problem that you are seeing? From the code that you've posted, it looks like you are performing a GET to retrieve some customer data, but the ng-repeat is looking at itemList, which I don't see defined it your code. Commented Apr 15, 2019 at 11:30
  • yes, i have retrieve data and this data response set to input field @BrendanGreen Commented Apr 15, 2019 at 11:50
  • you want the response data to be set to your input elements? Commented Apr 15, 2019 at 12:18
  • yes i want @FakharAhmadRasul Commented Apr 15, 2019 at 12:32

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.