使用AngularJS向下滚动页面时加载数据
向下滚动时,使用使用AngularJS向下滚动页面时加载数据,angularjs,Angularjs,向下滚动时,使用angular加载数据(json)的正确方法是什么?我们所做的是创建一个绑定到窗口滚动事件的指令,并调用一个scope函数来加载数据 或者您可以使用。我们所做的是生成一个绑定到窗口滚动事件的指令,并调用一个scope函数来加载数据 或者您可以使用。我们所做的是生成一个绑定到窗口滚动事件的指令,并调用一个scope函数来加载数据 或者您可以使用。我们所做的是生成一个绑定到窗口滚动事件的指令,并调用一个scope函数来加载数据 或者您可以使用。HTML <div id="fix
angular
加载数据(json)的正确方法是什么?我们所做的是创建一个绑定到窗口滚动事件的指令,并调用一个scope函数来加载数据
或者您可以使用。我们所做的是生成一个绑定到窗口滚动事件的指令,并调用一个scope函数来加载数据
或者您可以使用。我们所做的是生成一个绑定到窗口滚动事件的指令,并调用一个scope函数来加载数据
或者您可以使用。我们所做的是生成一个绑定到窗口滚动事件的指令,并调用一个scope函数来加载数据 或者您可以使用。HTML
<div id="fixed" when-scrolled="loadMore()">
<ul>
<li ng-repeat="i in items">{{product.name}}</li>
</ul>
</div>
- {{product.name}
JS
app.controller("MainController", function($scope, $http){
var counter = 0;
$scope.products = [];
$scope.loadMore = function() {
for (var i = 0; i < 10; i++) {
$scope.products.push({name: counter});
counter += 10;
}
};
$scope.loadMore();
}]);
myApp.directive("whenScrolled", function(){
return{
restrict: 'A',
link: function(scope, elem, attrs){
// we get a list of elements of size 1 and need the first element
raw = elem[0];
// we load more elements when scrolled past a limit
elem.bind("scroll", function(){
if(raw.scrollTop+raw.offsetHeight+5 >= raw.scrollHeight){
scope.loading = true;
// we can give any function which loads more elements into the list
scope.$apply(attrs.whenScrolled);
}
});
}
}
});
app.controller(“MainController”,函数($scope,$http){
var计数器=0;
$scope.products=[];
$scope.loadMore=函数(){
对于(变量i=0;i<10;i++){
$scope.products.push({name:counter});
计数器+=10;
}
};
$scope.loadMore();
}]);
myApp.directive(“whenScrolled”,function()){
返回{
限制:“A”,
链接:功能(范围、要素、属性){
//我们得到一个大小为1的元素列表,需要第一个元素
原始=元素[0];
//当滚动超过限制时,我们加载更多的元素
元素绑定(“滚动”,函数(){
if(原始滚动顶部+原始偏移视线+5>=原始滚动高度){
scope.loading=true;
//我们可以给任何函数加载更多的元素到列表中
适用范围:$apply(滚动时的属性);
}
});
}
}
});
工作示例:?HTML
<div id="fixed" when-scrolled="loadMore()">
<ul>
<li ng-repeat="i in items">{{product.name}}</li>
</ul>
</div>
- {{product.name}
JS
app.controller("MainController", function($scope, $http){
var counter = 0;
$scope.products = [];
$scope.loadMore = function() {
for (var i = 0; i < 10; i++) {
$scope.products.push({name: counter});
counter += 10;
}
};
$scope.loadMore();
}]);
myApp.directive("whenScrolled", function(){
return{
restrict: 'A',
link: function(scope, elem, attrs){
// we get a list of elements of size 1 and need the first element
raw = elem[0];
// we load more elements when scrolled past a limit
elem.bind("scroll", function(){
if(raw.scrollTop+raw.offsetHeight+5 >= raw.scrollHeight){
scope.loading = true;
// we can give any function which loads more elements into the list
scope.$apply(attrs.whenScrolled);
}
});
}
}
});
app.controller(“MainController”,函数($scope,$http){
var计数器=0;
$scope.products=[];
$scope.loadMore=函数(){
对于(变量i=0;i<10;i++){
$scope.products.push({name:counter});
计数器+=10;
}
};
$scope.loadMore();
}]);
myApp.directive(“whenScrolled”,function()){
返回{
限制:“A”,
链接:功能(范围、要素、属性){
//我们得到一个大小为1的元素列表,需要第一个元素
原始=元素[0];
//当滚动超过限制时,我们加载更多的元素
元素绑定(“滚动”,函数(){
if(原始滚动顶部+原始偏移视线+5>=原始滚动高度){
scope.loading=true;
//我们可以给任何函数加载更多的元素到列表中
适用范围:$apply(滚动时的属性);
}
});
}
}
});
工作示例:?HTML
<div id="fixed" when-scrolled="loadMore()">
<ul>
<li ng-repeat="i in items">{{product.name}}</li>
</ul>
</div>
- {{product.name}
JS
app.controller("MainController", function($scope, $http){
var counter = 0;
$scope.products = [];
$scope.loadMore = function() {
for (var i = 0; i < 10; i++) {
$scope.products.push({name: counter});
counter += 10;
}
};
$scope.loadMore();
}]);
myApp.directive("whenScrolled", function(){
return{
restrict: 'A',
link: function(scope, elem, attrs){
// we get a list of elements of size 1 and need the first element
raw = elem[0];
// we load more elements when scrolled past a limit
elem.bind("scroll", function(){
if(raw.scrollTop+raw.offsetHeight+5 >= raw.scrollHeight){
scope.loading = true;
// we can give any function which loads more elements into the list
scope.$apply(attrs.whenScrolled);
}
});
}
}
});
app.controller(“MainController”,函数($scope,$http){
var计数器=0;
$scope.products=[];
$scope.loadMore=函数(){
对于(变量i=0;i<10;i++){
$scope.products.push({name:counter});
计数器+=10;
}
};
$scope.loadMore();
}]);
myApp.directive(“whenScrolled”,function()){
返回{
限制:“A”,
链接:功能(范围、要素、属性){
//我们得到一个大小为1的元素列表,需要第一个元素
原始=元素[0];
//当滚动超过限制时,我们加载更多的元素
元素绑定(“滚动”,函数(){
if(原始滚动顶部+原始偏移视线+5>=原始滚动高度){
scope.loading=true;
//我们可以给任何函数加载更多的元素到列表中
适用范围:$apply(滚动时的属性);
}
});
}
}
});
工作示例:?HTML
<div id="fixed" when-scrolled="loadMore()">
<ul>
<li ng-repeat="i in items">{{product.name}}</li>
</ul>
</div>
- {{product.name}
JS
app.controller("MainController", function($scope, $http){
var counter = 0;
$scope.products = [];
$scope.loadMore = function() {
for (var i = 0; i < 10; i++) {
$scope.products.push({name: counter});
counter += 10;
}
};
$scope.loadMore();
}]);
myApp.directive("whenScrolled", function(){
return{
restrict: 'A',
link: function(scope, elem, attrs){
// we get a list of elements of size 1 and need the first element
raw = elem[0];
// we load more elements when scrolled past a limit
elem.bind("scroll", function(){
if(raw.scrollTop+raw.offsetHeight+5 >= raw.scrollHeight){
scope.loading = true;
// we can give any function which loads more elements into the list
scope.$apply(attrs.whenScrolled);
}
});
}
}
});
app.controller(“MainController”,函数($scope,$http){
var计数器=0;
$scope.products=[];
$scope.loadMore=函数(){
对于(变量i=0;i<10;i++){
$scope.products.push({name:counter});
计数器+=10;
}
};
$scope.loadMore();
}]);
myApp.directive(“whenScrolled”,function()){
返回{
限制:“A”,
链接:功能(范围、要素、属性){
//我们得到一个大小为1的元素列表,需要第一个元素
原始=元素[0];
//当滚动超过限制时,我们加载更多的元素
元素绑定(“滚动”,函数(){
if(原始滚动顶部+原始偏移视线+5>=原始滚动高度){
scope.loading=true;
//我们可以给任何函数加载更多的元素到列表中
适用范围:$apply(滚动时的属性);
}
});
}
}
});
工作示例:?虚拟滚动:仅显示视口中的一小部分数据,并在用户滚动时不断更改记录。它保持DOM元素的数量不变,因此提高了应用程序的性能 这篇文章非常有用
虚拟滚动:仅显示视口中的一小部分数据,并在用户滚动时不断更改记录。它保持DOM元素的数量不变,因此提高了应用程序的性能 这篇文章非常有用
虚拟滚动:仅显示视口中的一小部分数据,并在用户滚动时不断更改记录。它保持DOM元素的数量不变,因此提高了应用程序的性能 这篇文章非常有用
虚拟滚动:仅显示视口中的一小部分数据,并在用户滚动时不断更改记录。它保持DOM元素的数量不变,因此提高了应用程序的性能 这篇文章非常有用
提供链接是死链接提供链接是死链接提供链接是死链接提供链接是死投票,因为这是我要找的。作为一个程序员,我不需要详细的信息,我只是检查代码,然后我自己检查这个代码块是否有用。谢谢干杯因为这就是我要找的。