In my app.html I have:
<div id="wrapper"
(document:load)="onWindowLoadOrResize($event)"
(window:resize)="onWindowLoadOrResize($event)">
This is used to set the height on the css for a content div. The resize is working fine, but it does not fire initially on the page load. The document:load does not fire at all. What is the best way to run code that will see the initial size of the window?
At this point in your application, document.load is already fired. Easiest for you would probably be to do call the resizing function from your app-components constructor. At this point your DOM is ready, and the application is firing up. Also, you should assign the height value to a property in your app that the template can bind to rather than do DOM manipulation directly.
export class Application implements OnInit {
ngOnInit() {
window.onresize = this.onWindowLoadOrResize;
this.onWindowLoadOrResize();
}
private onWindowLoadOrResize() {
//TODO: your logic
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With