【发布时间】:2017-04-27 21:15:28
【问题描述】:
我有一个 Angularjs 示例 snippet。这里使用 ng-repeat 指令在表格中显示名称,我计划添加 ng-style 指令以根据表格行数向表格添加垂直滚动条。我怎样才能使下面的代码工作?
例如:只有当表格行数超过 4 时,我们才需要垂直滚动条到表格 我试过这样
<div ng-if= "names.length > 4" ng-style="{'overflow-y': 'auto'}" >
<table>
---------
</table>
</div>
请帮忙改正代码
这里是示例代码
<!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>
</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>
【问题讨论】:
标签: javascript html css angularjs angularjs-directive