我在长列表视图中有很多项目。我的用户如何通过访问 mypage.html#the_item_id 跳转到(即书签)到特定项目?
实际上,当我使用内联视图 [Sample 1] 时可以,但当我使用局部视图 [Sample 2] 时不会。在后一种情况下是否存在错误,或者我必须使用任何解决方法?
提前致谢!
示例 1:您可以访问 page.html#a100 以查看 item 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 所需的 scroll_view.html::
<div>
  <ul>
    <li ng-repeat="i in items"><a id='a{{i.id}}'>{{i.id}}</a></li>
  </ul>
</div>