: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