/#/invoices/1?tab=2 のようなリンクを使用して、シングル ページ アプリケーションのページに移動したいと考えています。このページにはタブが含まれているため、URL を介して希望するタブにユーザーを直接送信したいと考えています。
これを最もクリーンな方法で実装する方法について、いくつかの指針を提供できますか?
$anchorScrollメソッドを使用してクラス名を渡すと、その要素に直接移動できます。
上記の回答を更新するだけです。
カスタム ディレクティブを使用したいくつかの例
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
}
});
});
}
};
});