In my application, a user can switch between multiple tabs. Each tab is linked to a different component.
Example: User is on URL1, on button click he navigates to URL2 in a new tab. When I manually switch back to URL1, is there any method which is triggered just like onResume
function in Android
?
You can use @HostListener
on window
's focus
event on your component like below.
export class AnyComponent implements OnInit {
@HostListener('window:focus', ['$event'])
tabActivation(event) {
console.log("TAb activated")
}
}
You can also use blur
event to detect "deactivation" of tab.
@HostListener('window:blur', ['$event'])
tabDeactivation(event) {
console.log("TAb deactivated")
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.