Angularjs 角函数无法识别
每次用户接近底部时,我需要加载20个表项,其中包含600个表项。我以这种方式使用onscroll,但它无法识别角度函数,在本例中为loadMore():Angularjs 角函数无法识别,angularjs,onscroll,Angularjs,Onscroll,每次用户接近底部时,我需要加载20个表项,其中包含600个表项。我以这种方式使用onscroll,但它无法识别角度函数,在本例中为loadMore(): {{$index+1}} {{x.city} var-app=angular.module('myApp',[]); app.controller('customersCtrl',函数($scope,$http){ $scope.limit=20; $http.get('city.json')。然后(函数(响应){ $scope.city=r
{{$index+1}}
{{x.city}
var-app=angular.module('myApp',[]);
app.controller('customersCtrl',函数($scope,$http){
$scope.limit=20;
$http.get('city.json')。然后(函数(响应){
$scope.city=response.data;
});
$scope.loadMore=function(){
$scope.limit=$scope.limit+20;
}
});
所以,我得到了这个错误:
ReferenceError:loadMore未定义onscroll正在搜索JavaScript函数,不在角度范围内。。您需要在该元素上的register scroll事件中写入一个指令,并将回调传递给指令,如
my scroll=“loadMore()”
您应该使用一个指令,如ng infinite scroll
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<div id="tabla" onscroll="loadMore()">
<table>
<tr ng-repeat="x in city | limitTo: limit:begin">
<td> {{ $index +1 }} </td>
<td> {{ x.city }} </td>
</tr>
</table>
</div>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$scope.limit = 20;
$http.get('city.json').then(function (response) {
$scope.city = response.data;
});
$scope.loadMore= function(){
$scope.limit = $scope.limit+20;
}
});
</script>
</body>
</html>