I have a simple function, checking the width of the window and according to that value it stretches the content. But when I resize the page and reload the site, nothing happens until I resize the window. How do I call a function on page load in angular2?
My whole app.component.ts file:
import { Component } from '@angular/core';
@Component({
templateUrl: './app.component.html'
})
export class appComponent {
private checkScreenWidth() {
if (window.innerWidth < 1000 && window.innerWidth > 499) {
...
} else if (window.innerWidth < 500) {
...
} else {
...
}
}
}
ngOnInitorngAfterViewInit? Have you read up on the lifecycle hooks? What have you tried?