Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular-如何在不使用id的情况下从一个页面链接到另一个页面并滚动到ionic中的锚点_Javascript_Angularjs_Ionic Framework - Fatal编程技术网

Javascript Angular-如何在不使用id的情况下从一个页面链接到另一个页面并滚动到ionic中的锚点

Javascript Angular-如何在不使用id的情况下从一个页面链接到另一个页面并滚动到ionic中的锚点,javascript,angularjs,ionic-framework,Javascript,Angularjs,Ionic Framework,我正在开发一款爱奥尼亚应用程序。它在我的主页上有一个文章列表,每篇文章都有一个评论图标,可以作为文章页面中评论部分的链接 我如何从头版链接到文章页面评论部分的锚 已更新 由于Angular在#之后使用了“URL”,所以答案中建议,通过id链接到锚点是行不通的,所以我正在寻找另一种方法。 我已经尝试了几种解决方案,但没有一种不起作用 在这里,有时我会得到一个正确的顶部偏移值,但当我切换到另一个文章页面时,该值保持不变 这是我所做的代码: 文章列表视图: <a ng-click="commen

我正在开发一款爱奥尼亚应用程序。它在我的主页上有一个文章列表,每篇文章都有一个评论图标,可以作为文章页面中评论部分的链接

我如何从头版链接到文章页面评论部分的锚

已更新

由于Angular在#之后使用了“URL”,所以答案中建议,通过id链接到锚点是行不通的,所以我正在寻找另一种方法。 我已经尝试了几种解决方案,但没有一种不起作用

在这里,有时我会得到一个正确的顶部偏移值,但当我切换到另一个文章页面时,该值保持不变

这是我所做的代码:

文章列表视图:

<a ng-click="commentLink({{article.id}})">
              <img class="social-images" src="icons/comment.svg"/> {{ article.comments.length }}
            </a>
我也尝试过这个,基于一个this,但仍然没有运气:

控制器:

$scope.commentLink = function(articleId) {
    return $state.go('main.article', {id: articleId}).then(function(state) {
      var position = $ionicPosition.offset(angular.element(document.getElementsByName('comments-section')));
      console.log(position.top);
      $ionicScrollDelegate.scrollTo(position.left, position.top);
    })
  };
$location.hash('comments-section');
  var handle = $ionicScrollDelegate.$getByHandle('articleDelegate');
  handle.anchorScroll(true);
$scope.goToComment = function() {
  return $state.go('whatever the comment state is',           {param:param}).then(function(state) {
    $location.hash('new-comment');
    $ionicScrollDelegate.anchorScroll(true)
  })
 }
视图:


如果您的评论部分有一个id(例如id=“new comment”),那么您可以从首页尝试:

<a ng-click="goToComment()">...</a>

我刚刚测试过,第一次点击它时,它似乎不起作用,它也似乎不刷新,或者它正在记住状态,因为当它开始工作时,当我点击正常链接时,在我已经使用锚链接进入之前的页面之后,它似乎记住了这一点,并在该锚点上打开页面,url具有该散列@拉德默斯
<a ng-click="goToComment()">...</a>
$scope.goToComment = function() {
  return $state.go('whatever the comment state is',           {param:param}).then(function(state) {
    $location.hash('new-comment');
    $ionicScrollDelegate.anchorScroll(true)
  })
 }