Angular导航到页面上的特定选项卡

时间:2014-04-04 11:47:42

标签: angularjs ngroute

我想使用/#/ invoices / 1?tab = 2这样的链接导航到我的单页应用程序的页面。此页面包含选项卡,因此我还希望通过URL直接将用户发送到我希望的选项卡。

您能否提供一些关于如何以最干净的方式实现这一点的指示?

2 个答案:

答案 0 :(得分:0)

使用$anchorScroll方法,在其上传递类名,您可以直接转到该元素。

答案 1 :(得分:0)

只是对上述答案的更新。

自定义指令的几个例子

http://nadeemkhedr.com/angularjs-scroll-to-element-using-directives/

 angular.module('MyApp').directive('scrollToBookmark', function() {  
  return {
    link: function(scope, element, attrs) {
      var value = attrs.scrollToBookmark;
      element.click(function() {
        scope.$apply(function() {
          var selector = "[scroll-bookmark='"+ value +"']";
          var element = $(selector);
          if(element.length) {
            window.scrollTo(0, element[0].offsetTop – 100); 
            // Don’t want the top to be the exact element, -100 will go to the top for a little bit more
          }
        });
      });
    }
  };
});
相关问题