在“通过ID滚动到一个元素”中,如果我们有多个div,将影响哪个滚动,每个div在Controller范围内都有一个滚动。在下面的示例中,如何将滚动设置为我刚刚添加的最新项目?任何帮助,谢谢!
这是我的脚本:
app.controller('MainCtrl', function($scope, $location, $anchorScroll) {
var i = 1;
$scope.people = [{"name": John,
"items": [{ id: 1, name: 'Item 1' }]},
{"name": Tom,
"items": [{ id: 1, name: 'Item 1' }]},
]
$scope.addItem = function (index){
i++;
$scope.people[index].items.push({ id: i, name: 'Item ' + i});
$location.hash('item' + i);
$anchorScroll();
};
这是我的html:
<div ng-controller = "MainCtrl" style="height:1000px; overflow:scroll">
<div ng-repeat="person in people" style="height:700px; overflow:scroll">{{person.name}}
<button ng-click="addItem($index)">Add Item </button>
<div style="height:500px; overflow:scroll"> //How to set this scroll to the latest item?
<ul>
<li ng-repeat="item in person.items" id="item{{item.id}}">{{item.name}}</li>
</ul>
</div>
</div>
</div>