http://plnkr.co/edit/7OnKAGvVNXWLwN5fZqJu?p=preview
我正在设置一个与无限滚动相关的问题,并注意到当我更新$scope.tags
数组时,一旦标签一直向上滚动,标签实际上并没有更新。
在我的项目中,我使用服务来获取新数据,但是在这个示例中,我只是重置tags
数组内部的值。
为什么它没有在 DOM 中更新?
标记:
<section id="tags-col" class="tag-column column">
<ul id="tags-panel-list">
<li ng-repeat="tag in tags">
<div class="tag">{{tag.term}}</div>
</li>
</ul>
</section>
<div>{{tags}}</div>
控制器:
// Tags panel Controller:
TagsPanelCtrl.$inject = ['$scope', '$timeout'];
function TagsPanelCtrl($scope, $timeout) {
var tagsCol = document.getElementById("tags-col");
$scope.tags = [
{ term: "tag1" },
{ term: "tag2" },
{ term: "tag3" },
{ term: "tag4" },
{ term: "tag5" },
{ term: "tag6" },
{ term: "tag7" },
{ term: "tag8" },
{ term: "tag9" },
{ term: "tag10"},
{ term: "tag1" },
{ term: "tag2" },
{ term: "tag3" },
{ term: "tag4" },
{ term: "tag5" },
{ term: "tag6" },
{ term: "tag7" },
{ term: "tag8" },
{ term: "tag9" },
{ term: "tag10"}
];
var scrollingElement = function(event) {
console.log(tagsCol.scrollHeight - tagsCol.scrollTop);
if ((tagsCol.scrollHeight - tagsCol.scrollTop) === tagsCol.offsetHeight) {
console.log('reached bottom!');
// Here you reach the bottom of the column,
// and I attempt to update the tags array
$scope.tags = [
{ term: "tag1" },
{ term: "tag2" },
{ term: "tag3" },
{ term: "tag4" },
{ term: "tag5" },
{ term: "tag6" },
{ term: "tag7" },
{ term: "tag8" },
{ term: "tag9" },
{ term: "tag10"},
{ term: "tag11"},
{ term: "tag12"},
{ term: "tag13"},
{ term: "tag14"},
{ term: "tag15"},
{ term: "tag16"},
{ term: "tag17"},
{ term: "tag18"},
{ term: "tag19"},
{ term: "tag20"},
{ term: "tag21"},
{ term: "tag22"},
{ term: "tag23"},
{ term: "tag24"},
{ term: "tag25"},
{ term: "tag26"},
{ term: "tag27"},
{ term: "tag28"},
{ term: "tag29"},
{ term: "tag30"}
];
}
};
document.getElementById('tags-col').addEventListener('scroll', scrollingElement);
}