René's URL Explorer Experiment


Title: Proposal: Provide Component Lifecycle Hooks as Observables · Issue #10185 · angular/angular · GitHub

Open Graph Title: Proposal: Provide Component Lifecycle Hooks as Observables · Issue #10185 · angular/angular

X Title: Proposal: Provide Component Lifecycle Hooks as Observables · Issue #10185 · angular/angular

Description: I'm submitting a ... [ ] bug report [x] feature request [ ] support request Current behavior Currently, component lifecycle hooks are handled by implementing one or more interfaces provided by angular. I find myself often wanting to subs...

Open Graph Description: I'm submitting a ... [ ] bug report [x] feature request [ ] support request Current behavior Currently, component lifecycle hooks are handled by implementing one or more interfaces provided by angu...

X Description: I'm submitting a ... [ ] bug report [x] feature request [ ] support request Current behavior Currently, component lifecycle hooks are handled by implementing one or more interfaces provided by ...

Opengraph URL: https://github.com/angular/angular/issues/10185

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Proposal: Provide Component Lifecycle Hooks as Observables","articleBody":"**I'm submitting a ...** \n\n```\n[ ] bug report\n[x] feature request\n[ ] support request\n```\n\n**Current behavior**\n     Currently, component lifecycle hooks are handled by implementing one or more interfaces provided by angular. I find myself often wanting to subscribe to an observable until the component/directive is destroyed. To do this, I have to have a member for each subscription for later disposal in the `ngOnDestroy()` method.\nExample:\n\n``` typescript\n/* imports */\n\n@Directive({\n  selector: '[onDrag]'\n})\nexport class OnDrag implements OnInit, OnDestroy {\n  dragStart: Subscription;\n  dragEnter: Subscription;\n  dragOver: Subscription;\n  dragLeave: Subscription;\n\n  constructor(private element: ElementRef) { }\n\n  ngOnInit(): any {\n    let elem = this.element.nativeElement;\n\n    this.dragStart = Observable.fromEvent(elem, 'dragstart')\n      .do(() =>{ /*do stuff*/ })\n      .subscribe();\n\n    this.dragEnter = Observable.fromEvent(elem, 'dragenter')\n      .do(() =>{ /*do stuff*/ })\n      .subscribe();\n\n    this.dragOver = Observable.fromEvent(elem, 'dragover')\n      .do(() =>{ /*do stuff*/ })\n      .subscribe();\n\n    this.dragLeave = Observable.fromEvent(elem, 'dragleave')\n      .do(() =>{ /*do stuff*/ })\n      .subscribe();\n\n    // etc...\n  }\n\n  ngOnDestroy(): any {\n    this.dragStart.unsubscribe();\n    this.dragEnter.unsubscribe();\n    this.dragOver.unsubscribe();\n    this.dragLeave.unsubscribe();\n  }\n}\n```\n\n**Desired behavior**\nMy suggestion is to provide components with an observable for each lifecycle event (via injection perhaps?). The above example could turn into something like:\n\n``` typescript\n/* imports */\n\n@Directive({\n  selector: '[onDrag]'\n})\nexport class OnDrag implements OnInit {\n  constructor(\n    private element: ElementRef,\n    private lifecycle: ThingWithLifecycleObservablesForThisComponent\n  ) { }\n\n  ngOnInit(): any {\n    let elem = this.element.nativeElement;\n\n    Observable.fromEvent(elem, 'dragstart')\n      .do(() =>{ /*do stuff*/ })\n      .takeUntil(this.lifecycle.ngDestroy$)\n      .subscribe();\n\n    Observable.fromEvent(elem, 'dragenter')\n      .do(() =>{ /*do stuff*/ })\n      .takeUntil(this.lifecycle.ngDestroy$)\n      .subscribe();\n\n    Observable.fromEvent(elem, 'dragover')\n      .do(() =>{ /*do stuff*/ })\n      .takeUntil(this.lifecycle.ngDestroy$)\n      .subscribe();\n\n    Observable.fromEvent(elem, 'dragleave')\n      .do(() =>{ /*do stuff*/ })\n      .takeUntil(this.lifecycle.ngDestroy$)\n      .subscribe();\n\n    // etc...\n  }\n}\n```\n\n**What is the motivation / use case for changing the behavior?**\nUltimately, I would like a way to not have to hold onto subscriptions as class members (perhaps there is a better way to achieve this than my suggestion). It could be convenient/concise to be able to handle lifecycle events as observables within components. As a workaround currently I have been extending my components with a base class that provides (some) of these events:\n\n``` typescript\nimport { OnInit, OnDestroy } from '@angular/core';\nimport { Subject } from 'rxjs/Subject';\n\nexport class ComponentLifeCycle implements OnInit, OnDestroy {\n  protected ngInit$: Subject\u003cany> = new Subject\u003cany>();\n  protected ngDestroy$: Subject\u003cany> = new Subject\u003cany>();\n\n  ngOnInit(): any {\n    this.ngInit$.next({});\n  }\n\n  ngOnDestroy(): any {\n    this.ngDestroy$.next({});\n  }\n}\n```\n\n**Please tell us about your environment:**\n- **Angular version:** 2.0.0-rc.4\n- **Browser:** all \n- **Language:** all\n","author":{"url":"https://github.com/Jeff-Cortese","@type":"Person","name":"Jeff-Cortese"},"datePublished":"2016-07-20T17:08:40Z","url":"https://github.com/angular/angular/issues/10185"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:c631d089-b18d-22f6-fbff-cef25516d975
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id97B8:1CEA6F:1BF293B:24CB321:6B014FB6
html-safe-nonce788dc888d0bd8c7f86bb0d03719dfa3f995fc692896b898ce839ce113f573ef1
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5N0I4OjFDRUE2RjoxQkYyOTNCOjI0Q0IzMjE6NkIwMTRGQjYiLCJ2aXNpdG9yX2lkIjoiNDE5ODM4NzU4MzY4NTg0MDgyMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmaca7afcb73f9e02e3b562fa53e7264ea60d1b4584ba2d71a7bbb3f46f1ab9bd355
hovercard-subject-tagissue:166633218
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/10185/issue_layout
twitter:imagehttps://opengraph.githubassets.com/5e2607eafb94e2d54ebe98e8c8c3a221482be584e06c1c589c2cea250339a9de/angular/angular/issues/10185
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/5e2607eafb94e2d54ebe98e8c8c3a221482be584e06c1c589c2cea250339a9de/angular/angular/issues/10185
og:image:altI'm submitting a ... [ ] bug report [x] feature request [ ] support request Current behavior Currently, component lifecycle hooks are handled by implementing one or more interfaces provided by angu...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameJeff-Cortese
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/angular/angular git https://github.com/angular/angular.git
octolytics-dimension-user_id139426
octolytics-dimension-user_loginangular
octolytics-dimension-repository_id24195339
octolytics-dimension-repository_nwoangular/angular
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id24195339
octolytics-dimension-repository_network_root_nwoangular/angular
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/angular/angular/issues/10185#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F10185
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F10185
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=angular%2Fangular
Reloadhttps://github.com/angular/angular/issues/10185
Reloadhttps://github.com/angular/angular/issues/10185
Reloadhttps://github.com/angular/angular/issues/10185
angularhttps://github.com/angular
angularhttps://github.com/angular/angular
Codehttps://github.com/angular/angular
Issues836 (836)https://github.com/angular/angular/issues
Pull requests141 (141)https://github.com/angular/angular/pulls
Discussionshttps://github.com/angular/angular/discussions
Actionshttps://github.com/angular/angular/actions
Projectshttps://github.com/angular/angular/projects
Security and quality40 (40)https://github.com/angular/angular/security
Insightshttps://github.com/angular/angular/insights
https://github.com/angular/angular
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/10185
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/10185
Proposal: Provide Component Lifecycle Hooks as Observableshttps://github.com/angular/angular/issues/10185#top
https://github.com/thePunderWoman
https://github.com/alxhub
https://github.com/AndrewKushnir
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
core: lifecycle hookshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20lifecycle%20hooks%22
cross-cutting: observableshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22cross-cutting%3A%20observables%22
featureLabel used to distinguish feature request from other issueshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22feature%22
feature: under considerationFeature request for which voting has completed and the request is now under considerationhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22feature%3A%20under%20consideration%22
freq2: mediumhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22freq2%3A%20medium%22
Backloghttps://github.com/angular/angular/milestone/82
https://github.com/Jeff-Cortese
Jeff-Cortesehttps://github.com/Jeff-Cortese
on Jul 20, 2016https://github.com/angular/angular/issues/10185#issue-166633218
Nexthttps://github.com/angular/angular/issues/10185?timeline_page=1
tboschhttps://github.com/tbosch
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
featureLabel used to distinguish feature request from other issueshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22feature%22
on Oct 4, 2016https://github.com/angular/angular/issues/10185#event-812390867
pkozlowski-opensourcehttps://github.com/pkozlowski-opensource
freq2: mediumhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22freq2%3A%20medium%22
on Oct 12, 2016https://github.com/angular/angular/issues/10185#event-820876263
https://github.com/bobvanderlinden
bobvanderlindenhttps://github.com/bobvanderlinden
on Aug 28, 2017https://github.com/angular/angular/issues/10185#issuecomment-325276994
https://github.com/sod
sodhttps://github.com/sod
on Sep 25, 2017https://github.com/angular/angular/issues/10185#issuecomment-331899192
https://github.com/bobvanderlinden
bobvanderlindenhttps://github.com/bobvanderlinden
on Sep 25, 2017https://github.com/angular/angular/issues/10185#issuecomment-331967306
https://github.com/Jeff-Cortese
Jeff-Cortesehttps://github.com/Jeff-Cortese
on Sep 25, 2017https://github.com/angular/angular/issues/10185#issuecomment-331995898
@ohjameshttps://github.com/ohjames
https://github.com/bygrace1986
bygrace1986https://github.com/bygrace1986
on Oct 6, 2017https://github.com/angular/angular/issues/10185#issuecomment-334728536
@sodhttps://github.com/sod
https://stackoverflow.com/questions/40737752/anuglar2-lifecycle-events-as-rxjs-observable/46572739#46572739https://stackoverflow.com/questions/40737752/anuglar2-lifecycle-events-as-rxjs-observable/46572739#46572739
https://github.com/insidewhy
insidewhyhttps://github.com/insidewhy
on Oct 9, 2017https://github.com/angular/angular/issues/10185#issuecomment-335119417
@bygrace1986https://github.com/bygrace1986
https://github.com/bygrace1986
bygrace1986https://github.com/bygrace1986
on Oct 9, 2017https://github.com/angular/angular/issues/10185#issuecomment-335266458
@ohjameshttps://github.com/ohjames
https://github.com/sandangel
sandangelhttps://github.com/sandangel
on Oct 9, 2017https://github.com/angular/angular/issues/10185#issuecomment-335294870
https://github.com/insidewhy
insidewhyhttps://github.com/insidewhy
on Oct 11, 2017https://github.com/angular/angular/issues/10185#issuecomment-335770063
https://github.com/mlc-mlapis
mlc-mlapishttps://github.com/mlc-mlapis
on Oct 11, 2017https://github.com/angular/angular/issues/10185#issuecomment-335785909
@ohjameshttps://github.com/ohjames
https://github.com/insidewhy
insidewhyhttps://github.com/insidewhy
on Oct 11, 2017https://github.com/angular/angular/issues/10185#issuecomment-335788976
@mlc-mlapishttps://github.com/mlc-mlapis
https://github.com/ohjames/observable-inputhttps://github.com/ohjames/observable-input
https://github.com/fabioemoutinho
fabioemoutinhohttps://github.com/fabioemoutinho
on Aug 29, 2022https://github.com/angular/angular/issues/10185#issuecomment-1230504772
https://github.com/tayambamwanza
tayambamwanzahttps://github.com/tayambamwanza
on Oct 10, 2022https://github.com/angular/angular/issues/10185#issuecomment-1272742804
https://github.com/niklaas
niklaashttps://github.com/niklaas
on Oct 10, 2022https://github.com/angular/angular/issues/10185#issuecomment-1273083696
https://github.com/tayambamwanza
tayambamwanzahttps://github.com/tayambamwanza
on Oct 10, 2022https://github.com/angular/angular/issues/10185#issuecomment-1273107868
@niklaashttps://github.com/niklaas
https://github.com/niklaas
niklaashttps://github.com/niklaas
on Oct 31, 2022https://github.com/angular/angular/issues/10185#issuecomment-1296836658
@niklaashttps://github.com/niklaas
passing in an observable explicitlyhttps://stackblitz.com/edit/angular-ivy-kqlgct?file=src/app/hello.component.ts
https://github.com/tayambamwanza
tayambamwanzahttps://github.com/tayambamwanza
on Oct 31, 2022https://github.com/angular/angular/issues/10185#issuecomment-1296846309
@niklaashttps://github.com/niklaas
passing in an observable explicitlyhttps://stackblitz.com/edit/angular-ivy-kqlgct?file=src/app/hello.component.ts
@tomastrajanhttps://github.com/tomastrajan
https://user-images.githubusercontent.com/11971384/198980105-ca44fc34-3bf8-4b7f-902a-7d62ceb57b4f.jpeg
https://github.com/csisy
csisyhttps://github.com/csisy
on Jan 11, 2023https://github.com/angular/angular/issues/10185#issuecomment-1378539289
#20682https://github.com/angular/angular/pull/20682
https://github.com/JeanMeche
JeanMechehttps://github.com/JeanMeche
on Mar 16, 2023https://github.com/angular/angular/issues/10185#issuecomment-1472909784
This PRhttps://github.com/angular/angular/pull/49154/files#diff-508a78c7ae7456260190375c3b624cdd2fd5219aee48375c9d848ea2f3f95395
https://github.com/gavinsawyer
gavinsawyerhttps://github.com/gavinsawyer
on Aug 5, 2023https://github.com/angular/angular/issues/10185#issuecomment-1666548114
thePunderWomanhttps://github.com/thePunderWoman
thePunderWomanhttps://github.com/thePunderWoman
jessicajaniukhttps://github.com/jessicajaniuk
on Apr 4, 2024https://github.com/angular/angular/issues/10185#event-12364427484
https://github.com/alxhub
alxhubhttps://github.com/alxhub
on Oct 10, 2024https://github.com/angular/angular/issues/10185#issuecomment-2405219278
alxhubhttps://github.com/alxhub
not plannedhttps://github.com/angular/angular/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Anot-planned
on Oct 10, 2024https://github.com/angular/angular/issues/10185#event-14592265071
https://github.com/apps/angular-automatic-lock-bot
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Nov 10, 2024https://github.com/angular/angular/issues/10185#issuecomment-2466518594
automatic conversation locking policyhttps://github.com/angular/angular/blob/f0fbced1c55bc8b8ed9df01cea99df42f3e7eae3/contributing-docs/auto-issue-locking.md
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Nov 10, 2024https://github.com/angular/angular/issues/10185#event-15239752051
Sign up for freehttps://github.com/signup?return_to=https://github.com/angular/angular/issues/10185
Sign in to commenthttps://github.com/login?return_to=https://github.com/angular/angular/issues/10185
AndrewKushnirhttps://github.com/AndrewKushnir
alxhubhttps://github.com/alxhub
thePunderWomanhttps://github.com/thePunderWoman
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
core: lifecycle hookshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20lifecycle%20hooks%22
cross-cutting: observableshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22cross-cutting%3A%20observables%22
featureLabel used to distinguish feature request from other issueshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22feature%22
feature: under considerationFeature request for which voting has completed and the request is now under considerationhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22feature%3A%20under%20consideration%22
freq2: mediumhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22freq2%3A%20medium%22
BacklogNo due datehttps://github.com/angular/angular/milestone/82
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.