Title: Make resolve results injectable in constructor · Issue #10838 · angular/angular · GitHub
Open Graph Title: Make resolve results injectable in constructor · Issue #10838 · angular/angular
X Title: Make resolve results injectable in constructor · Issue #10838 · angular/angular
Description: [ ] bug report => search github for a similar issue or PR before submitting [X] feature request [ ] support request First off, many thanks for your really great work on Angular. We love where this is going. Thanks! Current behavior Given...
Open Graph Description: [ ] bug report => search github for a similar issue or PR before submitting [X] feature request [ ] support request First off, many thanks for your really great work on Angular. We love where this ...
X Description: [ ] bug report => search github for a similar issue or PR before submitting [X] feature request [ ] support request First off, many thanks for your really great work on Angular. We love where th...
Opengraph URL: https://github.com/angular/angular/issues/10838
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Make resolve results injectable in constructor","articleBody":"```\n[ ] bug report => search github for a similar issue or PR before submitting\n[X] feature request\n[ ] support request\n```\n\nFirst off, many thanks for your really great work on Angular. We love where this is going. Thanks! \n\n**Current behavior**\n\nGiven a component:\n\n``` typescript\n@Component({\n template: require('./book-detail.html')\n})\nexport class BookDetail implements OnInit {\n\n private book : Book;\n\n constructor(private route: ActivatedRoute) {}\n\n ngOnInit(): void {\n this.route.data.subscribe((data: { book: Book }) => {\n this.book = data.book;\n });\n }\n\n}\n```\n\nAnd a resolver:\n\n``` typescript\n@Injectable()\nexport class BookDetailResolve implements Resolve\u003cany> {\n constructor(private bookService: BookService) {}\n\n resolve(route: ActivatedRouteSnapshot): Promise\u003cBook> {\n let id : number = _.toNumber(route.params['id']);\n return this.bookService.getBook(id);\n }\n}\n```\n\nAnd a configuration in the router: \n\n``` typescript\n path: ':id',\n component: BookDetail,\n resolve: {\n book: BookDetailResolve\n }\n```\n\nThe way a book is passed to BookDetail is now done by having BookDetail implement OnInit and using the ngInit to read the book from the ActivatedRoute.\n\n**Expected/desired behavior**\n\nIdeally, it would be possible to have the following code:\n\n``` typescript\n@Component({\n template: require('./book-detail.html')\n})\nexport class BookDetail {\n\n constructor(private book: Book) {}\n\n}\n```\n\nIn other words, the book as described in the route (and returned by BookDetailResolve) is injected directly into the constructor of BookDetail. This removes code which basically serves no purpose since resolve guarantees that all arguments are resolved prior to initializing the component. Code becomes predictable and the programming model is much easier to understand.\n\n**What is the motivation / use case for changing the behavior?**\n\nTo reduce code which serves only as boilerplate and strive towards a cleaner and easier-to-understand codebase.\n- **Angular version:** 2.0.0-rc.5","author":{"url":"https://github.com/robert-bor","@type":"Person","name":"robert-bor"},"datePublished":"2016-08-16T06:36:28Z","url":"https://github.com/angular/angular/issues/10838"}
| 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:348c3c0a-dc65-1874-18e8-500f6fd9c247 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BAAC:6DC60:1FF02C:27FB94:6B00FCF3 |
| html-safe-nonce | 401000b9d947678bc57c748cc7c6e7229192b5de23278d80582f471ac9f7973b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQUFDOjZEQzYwOjFGRjAyQzoyN0ZCOTQ6NkIwMEZDRjMiLCJ2aXNpdG9yX2lkIjoiOTE2NzAwMTgyNTU0NTYxNjYyOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 636be1f9767884fe239fa8b3369f661455720cbd4f76d3008aa46c3158fb5151 |
| hovercard-subject-tag | issue:171335784 |
| 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/10838/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d01bc450dfe98f2a798d2febd1709352200b42335bb7eeead89078c2353055ce/angular/angular/issues/10838 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d01bc450dfe98f2a798d2febd1709352200b42335bb7eeead89078c2353055ce/angular/angular/issues/10838 |
| og:image:alt | [ ] bug report => search github for a similar issue or PR before submitting [X] feature request [ ] support request First off, many thanks for your really great work on Angular. We love where this ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | robert-bor |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| 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 | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width