:https://material.angularjs.org/latest/demo/virtualRepeat角材料 - 无限滚动我用角材质的无限滚动,在此规定不工作
我的第一个问题是:这是否virtualRepeat需求与滚动条一个div里面,或者可以吧应用于整个页面?实际上我不想让我的内容在另一个div中使用额外的滚动条(除了浏览器之外)。
所以,我用$http
和我的服务回报30个项目,如果我提供的值为0,和60,如果我提供的1值等
var _page = 0;
$scope.infiniteItems = {
numLoaded_: 0,
toLoad_: 0,
// Required.
getItemAtIndex: function(index) {
if (index > this.numLoaded_) {
this.fetchMoreItems_(index);
return null;
}
return index;
},
// Required.
// For infinite scroll behavior, we always return a slightly higher
// number than the previously loaded items.
getLength: function() {
return this.numLoaded_ + 5;
},
fetchMoreItems_: function(index) {
// For demo purposes, we simulate loading more items with a timed
// promise. In real code, this function would likely contain an
// $http request.
if (this.toLoad_ < index) {
this.toLoad_ += 30;
postFactory.getPastPosts(_page).then(angular.bind(this, function(data) {
this.numLoaded_ = this.toLoad_;
_page++;
}));
}
}
};
这里是我的HTML
<md-content flex layout-padding>
<div class="virtualRepeatdemoInfiniteScroll">
<md-list>
<md-virtual-repeat-container id="vertical-container">
<div md-virtual-repeat="post in infiniteItems" md-on-demand="" class="repeated-item" flex="">
<md-divider></md-divider>
{{post}}
<past-post model="post" action="reaction(currentPost, candidate, type)"></past-post>
</div>
</md-virtual-repeat-container>
</span>
</md-list>
</div>
</md-content>
问题是没有任何反应。我没有得到任何价值。该问题可能也在postFactory.getPastPosts(_page).then(angular.bind(this, function(data) {
之内,因为数据实际上是data.data
,但文档中没有任何内容会显示数据的设置位置和方式。
UPDATE
为getPastPosts
的代码是非常简单的:一个基本的$http
要求:
function getPastPosts(page) {
return $http.get(baseUrl + '/api/content/past-posts/' + page)
}
我在应用程序的不同部分使用此所以毫无疑问,它的工作。
你尝试把一个断点,并检查里面有什么可用的'那么()'? – montrealist
你可以在你的问题中添加'postFactory'的代码吗? –
我已更新我的问题。 – uglycode