1
每當我的應用程序關閉時,我想銷燬在localStorage
中保存的令牌。以前我會做這樣的事情:Angular2 onbeforeunload
window.onbeforeunload = function (event) {
localStorage.removeItem('token');
};
我不知道怎麼弄內Angular2或在此功能把代碼,以便它執行每當應用程序被關閉。我的直覺告訴我把它放在我的應用程序級別的組件中,但我無法在google上找到答案。
您可以嘗試使用sessionStorage來代替。 http://stackoverflow.com/questions/37214101/ngondestroy-not-destroying-localstorage-token/37249612#37249612 –