Adeel Khan Adeel Khan - 16 days ago 7
Javascript Question

how to get array values from $scope variable angularjs

how to add Table row in button click event angularjs please check below image

<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

Answer

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>