When to use the AngularJS `$onInit` Life-Cycle Hook

Code has to be moved in the $onInit function, when it depends on bindings, because these bindings are not available within this in the constructor. They get assigned AFTER instantiation of the component class. Example: You have a state definition like this: $stateProvider.state(“app”, { url: “https://stackoverflow.com/”, views: { “indexView”: { component: “category” } }, resolve: … Read more