2

here is the html file

it contains a model popup with fields name and email id. I need to edit and update them

<tr ng-repeat="item in collection">
<a ng-click=readOne(item.id) data-toggle="modal" data-target="#myModal">Edit</a>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
    <div class="modal-content">
        <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="modal-product-title">Edit</h4>
    </div>
        <div class="modal-body">
        <div><b style='color: red'>{{modalstatustext}}</b></div>
            <form id="form-dinminder">
            <div class="form-group">
              <label for="name" class="control-label">Name</label>
              <input ng-model="name" type="text" class="form-control" id="form-name" placeholder="Name">                                            
           </div>
        <div class="form-group">
            <label for="email" class="control-label">Email ID</label>
            <input ng-model="email" type="text" class="form-control" id="form-email" placeholder="Email ID">
        </div>
    </form>
</div>
    <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    <button id="btn-update-product" type="button" class="btn btn-warning" ng-click="updateProduct()">Save changes</button>
      </div>
     </div>
    </div>
   </div>
 </td>
</tr>

controller.js

/***********edit************/
    $scope.readOne=function(id){
        console.log("selected agency id",id)
        adminservice.selectedAgency(id).then(function(response){
            $scope.aid = response.data[0].id;
            $scope.name=response.data[0].name;
            $scope.email=response.data[0].webaddress;

            //update modal
            $('#myModal').modal('show');

        },function(error){
            $scope.modalstatustext = "Unable to Update data!";
        });
    }

    $scope.updateProduct=function(id){

        var Name = $scope.name;
        var Email = $scope.email;
        service.updateAgency(Name,Email).then(function(response){
            //alert(response.data);         
             $('#myModal').modal('hide');
                 showAll();//after updating all items are shown
        },function(error){
            console.log("error in updating ");
        });

    }

service.js

var updateAgency=function(Name,Email){

    return $http({
        method: "POST",
        url: CONFIG.apiurl + 'edit',
        params:{
            name:Name,
            webaddress:Email
        }
    }); 

i have no idea what i have done wrong. Backend seems to work perfectly. thanks

2
  • could you please provide the error if there is any on your console ? Commented Jul 10, 2017 at 5:01
  • there was no error only data was not passing correctly. I have corrected the mistake by passing name and email from ng-click Commented Jul 10, 2017 at 5:46

2 Answers 2

1

Your UpdateProduct function expects a parameter of id,

   <button id="btn-update-product" type="button" class="btn btn-warning" ng-click="updateProduct(passidhere)">Save changes</button>
Sign up to request clarification or add additional context in comments.

Comments

0

Remove the id parameter from your updateProduct function as this is not used.

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.