我有很多項目在一個很長的列表視圖。我的用戶如何通過訪問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