Angular 6 LifeCycle hooks / events are not being called.
If lifecycle hooks of your Angular 6 application are not being called then check whether your functions are using arrow function syntax. I have this issue and after some googling i found the solution.
The issue is that I was using the arrow function syntax (
=>
) like this:class MyComponent implements OnInit {
public ngOnInit = () => {
console.log("ngOnInit");
}
}
Apparently that does not work in Angular 6. Using non-arrow function syntax fixes the issue:
class MyComponent implements OnInit {
public ngOnInit() {
console.log("ngOnInit");
}
}
Comments
Post a Comment