Title: destructor option for service providers · Issue #11228 · angular/angular · GitHub
Open Graph Title: destructor option for service providers · Issue #11228 · angular/angular
X Title: destructor option for service providers · Issue #11228 · angular/angular
Description: [ ] bug report => search github for a similar issue or PR before submitting [X ] feature request [ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md...
Open Graph Description: [ ] bug report => search github for a similar issue or PR before submitting [X ] feature request [ ] support request => Please do not submit support request here, instead see https://github.com/ang...
X Description: [ ] bug report => search github for a similar issue or PR before submitting [X ] feature request [ ] support request => Please do not submit support request here, instead see https://github.c...
Opengraph URL: https://github.com/angular/angular/issues/11228
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"destructor option for service providers","articleBody":"```\n[ ] bug report => search github for a similar issue or PR before submitting\n[X ] feature request\n[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\n```\n\n**Current behavior**\nSee example below:\n\n```\n@Injectable()\nexport class GlobalServiceProvidedInBootstrap {\n public subscribe(f: Function);\n public unsubscribe(f: Function);\n}\n```\n\n```\nexport function callback() {\n};\n\n@Injectable()\nexport class ServiceProvidedInElement {\n constructor(public service: GlobalServiceProvidedInBootstrap) {\n service.subscribe(callback);\n }\n}\n```\n\n```\n@Component({\n selector: 'example-tag',\n providers: [ServiceProvidedInElement]\n})\nexport class ExampleTagComponent {\n constructor(private s: ServiceProvidedInElement) {\n }\n public ngOnDestroy() {\n this.s.service.unsubscribe(callback);\n }\n}\n```\n\nThe problem I'm having in similar code is that the moment this component is destroyed, there is no way for me to unsubscribe ServiceProvidedInElement from GlobalServiceProvidedInBootstrap unless I use ngOnDestroy in the component.\n\n**Expected/desired behavior**\nThe expected behavior is that when I declare my providers, I should be able to set a callback to destroy my service provided. So instead of using ngOnDestroy I could do it like this:\n\n```\nexport SERVICE_PROVIDED_IN_ELEMENT_PROVIDERS = [\n {\n token: ServiceProvidedInElement,\n useDestructor: function (element: ServiceProvidedInElement) {\n element.service.unsubscribe(callback);\n }\n }\n];\n```\n","author":{"url":"https://github.com/pjordaan","@type":"Person","name":"pjordaan"},"datePublished":"2016-09-01T08:42:06Z","url":"https://github.com/angular/angular/issues/11228"}
| 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:253636ea-34dc-ef96-df48-143ad6f6f1c3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E184:1201C:1BA540B:24BB226:6B0159CE |
| html-safe-nonce | a1aa94cf18ae702f762d160c3177cf7f024b881dea53767c9d09bf7eb57b08f1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTg0OjEyMDFDOjFCQTU0MEI6MjRCQjIyNjo2QjAxNTlDRSIsInZpc2l0b3JfaWQiOiI4OTExOTQzMTU2ODU4MTgyMDk0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 51e04e613b84779a3517e554d20a487f9a3f0b007d2963202743661d87b39eff |
| hovercard-subject-tag | issue:174467779 |
| 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/11228/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f3f6839e846f51cebd576882d7818d120d1f6425a40817e9560902c91d890a3f/angular/angular/issues/11228 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f3f6839e846f51cebd576882d7818d120d1f6425a40817e9560902c91d890a3f/angular/angular/issues/11228 |
| og:image:alt | [ ] bug report => search github for a similar issue or PR before submitting [X ] feature request [ ] support request => Please do not submit support request here, instead see https://github.com/ang... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pjordaan |
| 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