Title: ViewChild on component placed inside of template being used by other component is always set to same component · Issue #14835 · angular/angular · GitHub
Open Graph Title: ViewChild on component placed inside of template being used by other component is always set to same component · Issue #14835 · angular/angular
X Title: ViewChild on component placed inside of template being used by other component is always set to same component · Issue #14835 · angular/angular
Description: I'm submitting a ... (check one with "x") [x] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not submit support request here, instead see https://github.com/an...
Open Graph Description: I'm submitting a ... (check one with "x") [x] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not submit support request...
X Description: I'm submitting a ... (check one with "x") [x] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not su...
Opengraph URL: https://github.com/angular/angular/issues/14835
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ViewChild on component placed inside of template being used by other component is always set to same component","articleBody":"\u003c!--\r\nIF YOU DON'T FILL OUT THE FOLLOWING INFORMATION WE MIGHT CLOSE YOUR ISSUE WITHOUT INVESTIGATING\r\n-->\r\n\r\n**I'm submitting a ...** (check one with \"x\")\r\n```\r\n[x] bug report => search github for a similar issue or PR before submitting\r\n[ ] feature 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```\r\n\r\n**Current behavior**\r\nPlease look at [this Plunker](https://plnkr.co/edit/ulqFSi42Xwiyr1lLGXjW?p=preview).\r\nThis test case shows that the ViewChild for a component placed inside of a template used by another component will remain unchanged, although the actual component follows the expected lifecycle (construction, OnInit, OnDestroy).\r\n\r\n**Expected behavior**\r\nI expected that the ViewChild variable would be updated according to the InnerComponent actually in the DOM.\r\n\r\n**Minimal reproduction of the problem with instructions**\r\n- Go to [the Plunker](https://plnkr.co/edit/ulqFSi42Xwiyr1lLGXjW?p=preview).\r\n- When the application loads, we only have a \"Toggle content\" button. Click it, and a new InnerComponent (of index 1) will be constructed, and will go through its OnInit. The ViewChild for #inner in AppComponent is set to that InnerComponent of index 1.\r\n- Click \"Toggle content\" again, and the InnerComponent of index 1 will have its OnDestroy called and it will be removed from the DOM.\r\n- Click \"Toggle content\" again, and a new instance of the InnerComponent (of index 2) will be constructed, and its OnInit will be called. However, #inner will be set again to first InnerComponent of index 1.\r\n- Click \"Toggle content\" again, and the InnerComponent of index 2 will have its OnDestroy called and it will be removed from the DOM.\r\n- Every time you will make InnerComponent appear, #inner will still be called with the same InnerComponent of index 1.\r\n\r\n**What is the motivation / use case for changing the behavior?**\r\nIt is a big problem that what we see in the browser and the component we get at through the ViewChild are not the same. ViewChildren seems to be exhibiting the same problem.\r\n\r\n**Please tell us about your environment:**\r\nWindows 10\r\n\r\n* **Angular version:** 2.4.8\r\n\u003c!-- Check whether this is still an issue in the most recent Angular version -->\r\n\r\n* **Browser:** [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]\r\nAll\r\n \r\n* **Language:** [all | TypeScript X.X | ES6/7 | ES5]\r\nTypescript 2.0.3\r\n\r\n* **Node (for AoT issues):** `node --version` = \r\n","author":{"url":"https://github.com/marclerman","@type":"Person","name":"marclerman"},"datePublished":"2017-03-01T17:50:26Z","url":"https://github.com/angular/angular/issues/14835"}
| 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:4ef769c7-402a-5dc7-df4e-5c8ee12e772c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BD52:FC5BE:1CD790C:263BD71:6B0165C5 |
| html-safe-nonce | d642d6f189eb1f3a84be40ba0dbb69a4e050b0e0c9def19240bec84b9d7c4fa1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRDUyOkZDNUJFOjFDRDc5MEM6MjYzQkQ3MTo2QjAxNjVDNSIsInZpc2l0b3JfaWQiOiIyNzYyMzczNzIwNzYzODg0OTk4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8bb4867e1529933ed83b71b5188a9808e2d1175abc674d4e93936e85dc6d8407 |
| hovercard-subject-tag | issue:211158191 |
| 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/14835/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b33fb46be0bf5930542280a06a9cc87a5e32a87e0ff62088f74d21d73c90cc4f/angular/angular/issues/14835 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b33fb46be0bf5930542280a06a9cc87a5e32a87e0ff62088f74d21d73c90cc4f/angular/angular/issues/14835 |
| og:image:alt | I'm submitting a ... (check one with "x") [x] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not submit support request... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | marclerman |
| 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