0
如何做一個完整的頁面渲染,然後轉到錨點標記? 我正在做一個郵件鏈接,將鏈接到直接頁面,然後它將需要下降到特定的ID。 Iam通過Angular獲得ID,所以我需要在頁面嘗試去錨點之前加載頁面。在頁面加載後轉到錨點
id="{{idtoanchor}}"
什麼香港專業教育學院有角的嘗試:
app.controller('MainController', function ($scope, $http, $q, $anchorScroll, $location, $timeout)
首先嚐試:
$timeout(function() {
var currentURL = (document.URL);
var result = /[^/]*$/.exec(currentURL)[0];
$anchorScroll('#'+'result');
});
二:
$timeout(function() {
$location.hash('id');
$anchorScroll();
});
三的建議回答:
this.$onInit = function() {
var currentURL = (document.URL);
var result = /[^/]*$/.exec(currentURL)[0];
location.hash = "#" + result;
};
我似乎無法得到任何這些工作 即使我打電話$超時,它會在ng-repeat完成加載之前觸發。
我該如何在我的情況下使用它?當我想通過url去指定的錨標籤? –
您可以在'$ onInit'鉤子中編寫滾動代碼。 – souravb
不起作用,它在第一次通過www.url.com/something#id加載頁面時不會觸發,僅在頁面重新加載時觸發 –