-2

i have added new row but i want update new row data also in database but there is no updated data how to get new row data also add address json array

     <tr  ng-repeat="x in Profile.addresses">
       <td><input type="text" class="form-control" id="inputDefault"  ng-model='x.site_name ' name='site_name'></td>
       <td><input type="text" class="form-control" id="inputDefault"  ng-model='x.street_address ' name='street_address'></td>
  <td><input type="text" class="form-control" id="inputDefault"  ng-model='x.city ' name='city'></td>
    <td><input type="text" class="form-control" id="inputDefault"  ng-model='x.state ' name='state'></td>
 <td><input type="text" class="form-control" id="inputDefault"  ng-model='x.country ' name='country'></td>

    <tr ng-repeat="lines in array">

 <td><input type="text" class="form-control" id="inputDefault"  ng-model='x.site_name ' name='site_name'></td>
    <td><input type="text" class="form-control" id="inputDefault"  ng-model='x.street_address ' name='street_address'></td>
    <td><input type="text" class="form-control" id="inputDefault"  ng-model='x.city ' name='city'></td>
    <td><input type="text" class="form-control" id="inputDefault"  ng-model='x.state ' name='state'></td>
  <td><input type="text" class="form-control" id="inputDefault"  ng-model='x.country ' name='country'></td>
 <td><input type="text" class="form-control" id="inputDefault"  ng-model='x.zip_code ' name='zip_code'></td>
  <td><input type="text" class="form-control" id="inputDefault"  ng-model='x.phone_number ' name='phone_number'></td>

        </tr>

    <div class="col-md-2">

<a href="" data-toggle="tooltip" title="Add Address" ng-click="addRow()"><i class="fa fa-plus fa-2x cust_primary" aria-hidden="true">

enter image description here

1
  • you can use advantage of mvc of angular instead of trying to do dom manipulation Commented Nov 22, 2016 at 14:20

1 Answer 1

1

In your controller, create a counter and an array.

$scope.i = 0;
$scope.array = [];

Everytime your user clicks on the button, add one to the counter and create the array.

$scope.addRow = function() {
    $scope.i++;
    $scope.array = [];
    for(var i = 0; i < $scope.i; i++) {
        $scope.array.push(i);
    }
}

In your html, simply repeat the lines based on that counter.

<tr ng-repeat="lines in array">
    // Your tds
</tr>

EDIT Since I can't understand your english, I will give you a generic answer.

Your controller must have an array of objects

$scope.i = 0;
$scope.array = [{
    id: 0, 
    address: 'address 1', 
    name: 'Jack Reacher'
}, {
    id: 1, 
    address: 'address 2', 
    name: 'Ethan Hawk'
}];

you will then slightly change your addRow function.

$scope.addRow = function() {
    $scope.i++;
    $scope.array = [];
    for(var i = 0; i < $scope.i; i++) {
        $scope.array.push({
            id: null, 
            address: '', 
            name: ''
    });
    }
}

And in your HTML you use it.

<tr ng-repeat="object in array">
    <td>{{object.id}}</td>
    <td><input type="text" ng-model="object.address" /></td>
    <td><input type="text" ng-model="object.name" /></td>
</tr>

And if you want to save it, you use an $http request. I'll let you handle that part.

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

2 Comments

how to add these new add row values but current address address array ?
I'm sorry, can you rephrase ?

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.