I am working on an AngularJS project with a sample snippet that uses the ng-repeat directive to display names in a table. I want to add the ng-style directive to include a vertical scroll bar in the table based on the number of rows. How can I modify the code below to achieve this functionality?
For example, I only want the table to have a vertical scroll bar if there are more than 4 rows.
<div ng-if= "names.length > 4" ng-style="{'overflow-y': 'auto'}" >
<table>
----------
</table>
</div>
Please assist me in correcting the code above.
Here is the original code:
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<table>
<tr ng-repeat="x in names">
<td>{{ x.Name }}</td>
<td>{{ x.Country }}</td>
</tr>
</table>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://www.w3schools.com/angular/customers.php")
.then(function (response) {$scope.names = response.data.records;});
});
</script>
</body>
</html>