我有很多项目在一个很长的列表视图。我的用户如何通过访问mypage.html#the_item_id跳转到(即书签)特定项目?如何在角度的局部视图中跳转到锚点?
实际上,它可以当我使用内联视图[示例1],但不是当我使用局部视图[示例2]时。在后一种情况下是否存在错误,或者我是否必须使用任何解决方法?
在此先感谢!
示例1:您可以访问page.html中#A100看看项目100 ::
<!doctype html>
<html ng-app>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script>
<script>
function MainCtrl($scope){
$scope.items = [];
for(var i=0; i<200; i++){$scope.items.push({id: i})}
}
</script>
</head>
<body ng-controller='MainCtrl'>
<div>
<ul>
<li ng-repeat="i in items"><a id='a{{i.id}}'>{{i.id}}</a></li>
</ul>
</div>
</body>
</html>
示例2:不能访问page2.html#A100看看项目100,为什么呢? ::
<!doctype html>
<html ng-app>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script>
<script>
function MainCtrl($scope){
$scope.items = [];
for(var i=0; i<200; i++){$scope.items.push({id: i})}
}
</script>
</head>
<body ng-controller='MainCtrl'>
<div ng-include="'scroll_view.html'"><!-- MUST use "'...'" notation here --></div>
</body>
</html>
这是样品2 ::
<div>
<ul>
<li ng-repeat="i in items"><a id='a{{i.id}}'>{{i.id}}</a></li>
</ul>
</div>
我有完全相同的问题。你有没有找到解决方案?从我发现的问题是,jqlite'element.getElementById'在'scroll'函数中返回null。也许是因为内容不存在于DOM中呢? – NilsH