Title: bug(Lifecycle): Lifecycle hooks not called unless defined on the prototype · Issue #7270 · angular/angular · GitHub
Open Graph Title: bug(Lifecycle): Lifecycle hooks not called unless defined on the prototype · Issue #7270 · angular/angular
X Title: bug(Lifecycle): Lifecycle hooks not called unless defined on the prototype · Issue #7270 · angular/angular
Description: The lifecycle hooks (component, router) are called if defined on the class, or the function prototype, but are not called if defined in the constructor. class MyComponent implements OnInit { ngOnInit() { // works } } class MyComponent im...
Open Graph Description: The lifecycle hooks (component, router) are called if defined on the class, or the function prototype, but are not called if defined in the constructor. class MyComponent implements OnInit { ngOnIn...
X Description: The lifecycle hooks (component, router) are called if defined on the class, or the function prototype, but are not called if defined in the constructor. class MyComponent implements OnInit { ngOnIn...
Opengraph URL: https://github.com/angular/angular/issues/7270
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"bug(Lifecycle): Lifecycle hooks not called unless defined on the prototype","articleBody":"The lifecycle hooks (component, router) are called if defined on the class, or the function prototype, but are not called if defined in the constructor. \n\n``` js\nclass MyComponent implements OnInit {\n ngOnInit() { \n // works\n }\n}\n\nclass MyComponent implements OnInit {\n ngOnInit: any = () => {\n // no TypeScript warning, never called\n }\n}\n\nfunction MyComponent() {\n}\n\nMyComponent.prototype.ngOnInit = function() {\n // works\n};\n\nfunction MyComponent() {\n this.ngOnInit = function() {\n // never called\n };\n}\n```\n\nI expect the lifecycle hook to be called in either scenario. Is this by design?\n\ncc: @mhevery\n","author":{"url":"https://github.com/brandonroberts","@type":"Person","name":"brandonroberts"},"datePublished":"2016-02-25T01:54:21Z","url":"https://github.com/angular/angular/issues/7270"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:356ec336-e8f3-270b-1d4f-944dd45b855f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A836:EDA7A:1A0DBE7:21148F4:6B014A43 |
| html-safe-nonce | 266e4b4f54f4e45e61acc065bdf59197122f260e14444aa462be33bab23a03d9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODM2OkVEQTdBOjFBMERCRTc6MjExNDhGNDo2QjAxNEE0MyIsInZpc2l0b3JfaWQiOiI4Njk5MDc0MjMxMDkyMjAyMDUxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 15d5ab33ae7fda98259bbba66321733e47d81166e14eb05f8a5abe4d9a56a5f7 |
| hovercard-subject-tag | issue:136249804 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/7270/issue_layout |
| twitter:image | https://opengraph.githubassets.com/53d7b0417e8fb4ba1e94cc83fcd8dd14480545ec8c26b58b4ffa108ee1cb4eba/angular/angular/issues/7270 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/53d7b0417e8fb4ba1e94cc83fcd8dd14480545ec8c26b58b4ffa108ee1cb4eba/angular/angular/issues/7270 |
| og:image:alt | The lifecycle hooks (component, router) are called if defined on the class, or the function prototype, but are not called if defined in the constructor. class MyComponent implements OnInit { ngOnIn... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | brandonroberts |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width