Title: DI: provide an equivalent to @SkipSelf in Injector.get() · Issue #17898 · angular/angular · GitHub
Open Graph Title: DI: provide an equivalent to @SkipSelf in Injector.get() · Issue #17898 · angular/angular
X Title: DI: provide an equivalent to @SkipSelf in Injector.get() · Issue #17898 · angular/angular
Description: I'm submitting a ... [ ] Regression (behavior that used to work and stopped working in a new release) [ ] Bug report [x] Feature request [ ] Documentation issue or request [ ] Support request => Please do not submit support request here,...
Open Graph Description: I'm submitting a ... [ ] Regression (behavior that used to work and stopped working in a new release) [ ] Bug report [x] Feature request [ ] Documentation issue or request [ ] Support request => Pl...
X Description: I'm submitting a ... [ ] Regression (behavior that used to work and stopped working in a new release) [ ] Bug report [x] Feature request [ ] Documentation issue or request [ ] Support request =...
Opengraph URL: https://github.com/angular/angular/issues/17898
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"DI: provide an equivalent to @SkipSelf in Injector.get()","articleBody":"\u003c!--\r\nPLEASE HELP US PROCESS GITHUB ISSUES FASTER BY PROVIDING THE FOLLOWING INFORMATION.\r\n\r\nISSUES MISSING IMPORTANT INFORMATION MIGHT BE CLOSED WITHOUT INVESTIGATION.\r\n-->\r\n\r\n## I'm submitting a ...\r\n\u003c!-- Check one of the following options with \"x\" -->\r\n\u003cpre>\u003ccode>\r\n[ ] Regression (behavior that used to work and stopped working in a new release)\r\n[ ] Bug report \u003c!-- Please search github for a similar issue or PR before submitting -->\r\n[x] Feature request\r\n[ ] Documentation issue or request\r\n[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\r\n\u003c/code>\u003c/pre>\r\n\r\n## Current behavior\r\n\u003c!-- Describe how the issue manifests. -->\r\nIt is currently possible, when injecting a dependency in a constructor, to use `@Optional()` to avoid an error when the dependency is not found, and `@SkipSelf()` to search directly on the parent injector. For instance, a typical use case for `@SkipSelf()` is self-nested components that need to inject their parent.\r\n```typescript\r\nexport class MyComponent {\r\n constructor(@Optional() @SkipSelf() parent: MyComponent) {}\r\n}\r\n```\r\nWhen working with more \"dynamic\" dependency injection, however, you need to rely on an [Injector](https://github.com/angular/angular/blob/master/packages/core/src/di/injector.ts) object. It offers an equivalent to `@Optional()` by accepting a `notFoundValue`, but there is no way to emulate `@SkipSelf()`. The parent injector is not public, and the only method is `.get()` which will obviously look in this injector first.\r\n\r\n## Expected behavior\r\n\u003c!-- Describe what the desired behavior would be. -->\r\nThe `get()` method should accept a third optional argument allowing us to search directly on the parent injector:\r\n```typescript\r\nabstract get\u003cT>(token: Type\u003cT>|InjectionToken\u003cT>, notFoundValue?: T, skipSelf?: boolean): T;\r\n```\r\nIt would default to `false`, evidently.\r\n\r\n## What is the motivation / use case for changing the behavior?\r\n\u003c!-- Describe the motivation or the concrete use case. -->\r\nIt should be logical for `Injector` to offer the exact same capabilities as constructor-level dependency injection.\r\n\r\n## Please tell us about your environment\r\n\r\n\u003cpre>\u003ccode>\r\nAngular version: 4.2.5\r\n\u003c!-- Check whether this is still an issue in the most recent Angular version -->\r\n\u003c/code>\u003c/pre>\r\n","author":{"url":"https://github.com/youdz","@type":"Person","name":"youdz"},"datePublished":"2017-07-01T15:39:01Z","url":"https://github.com/angular/angular/issues/17898"}
| 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:439fae00-54c2-5cf3-589d-2e030ba31b4b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B806:EA09B:111B726:16B3C02:6B011763 |
| html-safe-nonce | 41e6154817ab2136139edc3f5f5914f02fe4cbefb084ab671d64bdb37842470b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODA2OkVBMDlCOjExMUI3MjY6MTZCM0MwMjo2QjAxMTc2MyIsInZpc2l0b3JfaWQiOiI4MjAzMDg2MDM5MDQwOTg5MDI3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | adfb626971a59a2fda95d7d18ed856d1f3fb918acf89ccde1eaeed5ab1015765 |
| hovercard-subject-tag | issue:239956158 |
| 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/17898/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2aaab50468e211d11a999d5d49cf35ad33f29a2b44b8758c55b8a9edb95bf588/angular/angular/issues/17898 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2aaab50468e211d11a999d5d49cf35ad33f29a2b44b8758c55b8a9edb95bf588/angular/angular/issues/17898 |
| og:image:alt | I'm submitting a ... [ ] Regression (behavior that used to work and stopped working in a new release) [ ] Bug report [x] Feature request [ ] Documentation issue or request [ ] Support request => Pl... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | youdz |
| 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