Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.onload in Angular

Is there any equivalent of window.onload event in Angular?

I want to fade out and remove my preloader but only after all resources like images are loaded. Since $viewConteneLoaded indicates only html insertion into view (i am using ngRotue) listening to it is not sufficient.

I would like to capture window.onload event, but don't know how to do it properly and what is the best-practice for doing it in Angular, so that digest would fire.

like image 953
julew2 Avatar asked Oct 15 '25 06:10

julew2


1 Answers

Write the following in the component file:

import { HostListener } from '@angular/core';

...

@HostListener('window:load')
onLoad() {
  console.log('is window:load');
}

...
like image 60
Roman Bondar Avatar answered Oct 17 '25 21:10

Roman Bondar