I submitted a bug report and a feature request on the link below: https://github.com/angular/angular/issues/20824 Github issue can be found here: The bug occurs when you try to detach * attach items between ViewContainers in angular. The bug is caused by a missing reparenting code in the angular core. I was not sure the nature of the problem it might have been inteded so that's why it is also a feature request. ## The Bug / Current behavior We are unable to detach a ViewRef from **ViewContainerRef A** and attach it to a different **ViewContainerRef B** Insert / Detaching doesn't trigger change detection on both ViewContainers. Using `@ContentChildren` fails to update changes properly. ## Expected behavior I would like to be able to detach a ViewRef and attach it to a new ViewContainer without recreating the components inside the view. This should work without any issues. ## Minimal reproduction of the problem with instructions https://stackblitz.com/edit/angular-gitter-couoxk?file=app%2Ftest.ts Manual parent attachment, interaction with underlying dom api is required. Uncomment the code in `test.ts` **LINE 118** to fix to see a workaround & expected behavior. The provided attachment logic seems to be missing from angular core located here: https://github.com/angular/angular/blob/5.1.x/packages/core/src/view/refs.ts#L192 ## What is the motivation / use case for changing the behavior? I have created a multi drag & drop library in angular, and this bug prevented me using the built in *ngFor due to errors being printed out in the console. Fixing this would help fellow developers to implement such a drag & drop without a hassle and without digging through the angular core codebase. This would allow to implement Drag & Drop that doesn't recreate the components when an item is dragged over. Would allow to manipulate dom without using nativeElement, No more worrying about *ngFor trying to find the changes and throwing errors when nodes are missing in dom. ## Possible solution Implement public api for ``*ngFor`` for detaching & attaching views between ViewContainers ```typescript attachView(view: ViewRef, index: number) { let template = (<any>this._template); let parentNodeDef = template._def; let parent = template._parentView; // The Important part!!! let viewRef = (<any>view); viewRef._view.root = parent.root; viewRef._view.parent = parent; viewRef._view.renderer = parent.renderer; viewRef._view.parentNodeDef = template._def; viewRef._view.state = 1 << 0; this.ViewContainer.insert(viewRef, index); } ``` The bug i caused by a missing marent assignment.l when reattaching the view to a new container. This assignment only occurs when the view is created. ```typescript viewRef._view.parent = parent; ``` ## Environment <pre><code> Angular version: 4.x and Angular version: 5.x <!-- Check whether this is still an issue in the most recent Angular version --> Browser: - [x] Chrome (desktop) version XX - [x] Chrome (Android) version XX - [x] Chrome (iOS) version XX - [x] Firefox version XX - [x] Safari (desktop) version XX - [x] Safari (iOS) version XX - [x] IE version XX - [x] Edge version XX - Platform: Mac, linux, Windows <br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@azarus/insert-detach-viewrefs-between-multiple-viewcontainerrefs">Utopian.io - Rewarding Open Source Contributors</a></em><hr/>
author | azarus | ||||||
---|---|---|---|---|---|---|---|
permlink | insert-detach-viewrefs-between-multiple-viewcontainerrefs | ||||||
category | utopian-io | ||||||
json_metadata | "{"links":["https://github.com/angular/angular/issues/20824","https://stackblitz.com/edit/angular-gitter-couoxk?file=app%2Ftest.ts","https://github.com/angular/angular/blob/5.1.x/packages/core/src/view/refs.ts#L192","https://utopian.io/utopian-io/@azarus/insert-detach-viewrefs-between-multiple-viewcontainerrefs"],"image":[],"tags":["utopian-io","angular","bug-report","programming","code"],"app":"utopian/1.0.0","format":"markdown+html","community":"utopian","type":"bug-hunting","repository":{"score":75.82821,"default_branch":"master","watchers":31539,"open_issues":2058,"forks":7829,"license":{"url":"https://api.github.com/licenses/mit","spdx_id":"MIT","name":"MIT License","key":"mit"},"open_issues_count":2058,"archived":false,"mirror_url":null,"forks_count":7829,"has_pages":false,"has_wiki":false,"has_downloads":true,"has_projects":true,"has_issues":true,"language":"TypeScript","watchers_count":31539,"stargazers_count":31539,"size":70915,"homepage":"https://angular.io","svn_url":"https://github.com/angular/angular","clone_url":"https://github.com/angular/angular.git","ssh_url":"git@github.com:angular/angular.git","git_url":"git://github.com/angular/angular.git","pushed_at":"2018-01-02T05:56:43Z","updated_at":"2018-01-02T06:56:55Z","created_at":"2014-09-18T16:12:01Z","deployments_url":"https://api.github.com/repos/angular/angular/deployments","releases_url":"https://api.github.com/repos/angular/angular/releases{/id}","labels_url":"https://api.github.com/repos/angular/angular/labels{/name}","notifications_url":"https://api.github.com/repos/angular/angular/notifications{?since,all,participating}","milestones_url":"https://api.github.com/repos/angular/angular/milestones{/number}","pulls_url":"https://api.github.com/repos/angular/angular/pulls{/number}","issues_url":"https://api.github.com/repos/angular/angular/issues{/number}","downloads_url":"https://api.github.com/repos/angular/angular/downloads","archive_url":"https://api.github.com/repos/angular/angular/{archive_format}{/ref}","merges_url":"https://api.github.com/repos/angular/angular/merges","compare_url":"https://api.github.com/repos/angular/angular/compare/{base}...{head}","contents_url":"https://api.github.com/repos/angular/angular/contents/{+path}","issue_comment_url":"https://api.github.com/repos/angular/angular/issues/comments{/number}","comments_url":"https://api.github.com/repos/angular/angular/comments{/number}","git_commits_url":"https://api.github.com/repos/angular/angular/git/commits{/sha}","commits_url":"https://api.github.com/repos/angular/angular/commits{/sha}","subscription_url":"https://api.github.com/repos/angular/angular/subscription","subscribers_url":"https://api.github.com/repos/angular/angular/subscribers","contributors_url":"https://api.github.com/repos/angular/angular/contributors","stargazers_url":"https://api.github.com/repos/angular/angular/stargazers","languages_url":"https://api.github.com/repos/angular/angular/languages","statuses_url":"https://api.github.com/repos/angular/angular/statuses/{sha}","trees_url":"https://api.github.com/repos/angular/angular/git/trees{/sha}","git_refs_url":"https://api.github.com/repos/angular/angular/git/refs{/sha}","git_tags_url":"https://api.github.com/repos/angular/angular/git/tags{/sha}","blobs_url":"https://api.github.com/repos/angular/angular/git/blobs{/sha}","tags_url":"https://api.github.com/repos/angular/angular/tags","branches_url":"https://api.github.com/repos/angular/angular/branches{/branch}","assignees_url":"https://api.github.com/repos/angular/angular/assignees{/user}","events_url":"https://api.github.com/repos/angular/angular/events","issue_events_url":"https://api.github.com/repos/angular/angular/issues/events{/number}","hooks_url":"https://api.github.com/repos/angular/angular/hooks","teams_url":"https://api.github.com/repos/angular/angular/teams","collaborators_url":"https://api.github.com/repos/angular/angular/collaborators{/collaborator}","keys_url":"https://api.github.com/repos/angular/angular/keys{/key_id}","forks_url":"https://api.github.com/repos/angular/angular/forks","url":"https://api.github.com/repos/angular/angular","fork":false,"description":"One framework. Mobile & desktop.","html_url":"https://github.com/angular/angular","private":false,"owner":{"site_admin":false,"type":"Organization","received_events_url":"https://api.github.com/users/angular/received_events","events_url":"https://api.github.com/users/angular/events{/privacy}","repos_url":"https://api.github.com/users/angular/repos","organizations_url":"https://api.github.com/users/angular/orgs","subscriptions_url":"https://api.github.com/users/angular/subscriptions","starred_url":"https://api.github.com/users/angular/starred{/owner}{/repo}","gists_url":"https://api.github.com/users/angular/gists{/gist_id}","following_url":"https://api.github.com/users/angular/following{/other_user}","followers_url":"https://api.github.com/users/angular/followers","html_url":"https://github.com/angular","url":"https://api.github.com/users/angular","gravatar_id":"","avatar_url":"https://avatars3.githubusercontent.com/u/139426?v=4","id":139426,"login":"angular"},"full_name":"angular/angular","name":"angular","id":24195339},"platform":"github","pullRequests":[],"moderator":{"account":"wehmoen","reviewed":true,"pending":false,"flagged":false}}" | ||||||
created | 2018-01-02 08:31:12 | ||||||
last_update | 2018-01-05 19:25:51 | ||||||
depth | 0 | ||||||
children | 5 | ||||||
last_payout | 2018-01-09 08:31:12 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 15.394 HBD | ||||||
curator_payout_value | 6.358 HBD | ||||||
pending_payout_value | 0.000 HBD | ||||||
promoted | 0.000 HBD | ||||||
body_length | 3,411 | ||||||
author_reputation | 4,239,423,105,752 | ||||||
root_title | "Insert / Detach ViewRefs between multiple ViewContainerRefs " | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||
percent_hbd | 10,000 | ||||||
post_id | 26,516,365 | ||||||
net_rshares | 2,238,656,925,484 | ||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
team | 0 | 42,550,535,972 | 5% | ||
mkt | 0 | 42,398,288,465 | 75% | ||
netuoso | 0 | 603,345,220,224 | 100% | ||
bobdos | 0 | 4,449,245,494 | 10% | ||
utopian-io | 0 | 1,539,771,216,541 | 0.94% | ||
habercitr | 0 | 2,138,963,023 | 25% | ||
utopy | 0 | 247,332,799 | 100% | ||
gnchmurat | 0 | 385,573,698 | 100% | ||
azarus | 0 | 151,715,670 | 100% | ||
boyrasyid | 0 | 230,572,500 | 100% | ||
tazysnow | 0 | 52,222,390 | 22.39% | ||
rakeshd | 0 | 1,119,872,481 | 100% | ||
cryptoprices | 0 | 1,096,662,681 | 100% | ||
motalee | 0 | 719,503,546 | 100% |
upvoted and followed...
author | gnchmurat |
---|---|
permlink | re-azarus-insert-detach-viewrefs-between-multiple-viewcontainerrefs-20180102t094304155z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-01-02 09:43:03 |
last_update | 2018-01-02 09:43:03 |
depth | 1 |
children | 0 |
last_payout | 2018-01-09 09:43:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 23 |
author_reputation | 1,296,965,930,680 |
root_title | "Insert / Detach ViewRefs between multiple ViewContainerRefs " |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 26,525,735 |
net_rshares | 74,243,838 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
azarus | 0 | 74,243,838 | 50% |
This is precisely the reason Utopian was created. I will be interested to see how much code was submitted to open source projects around the globe through Utopian.
author | netuoso | ||||||
---|---|---|---|---|---|---|---|
permlink | re-azarus-insert-detach-viewrefs-between-multiple-viewcontainerrefs-20180102t191337218z | ||||||
category | utopian-io | ||||||
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} | ||||||
created | 2018-01-02 19:13:36 | ||||||
last_update | 2018-01-02 19:13:36 | ||||||
depth | 1 | ||||||
children | 1 | ||||||
last_payout | 2018-01-09 19:13:36 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 0.000 HBD | ||||||
curator_payout_value | 0.000 HBD | ||||||
pending_payout_value | 0.000 HBD | ||||||
promoted | 0.000 HBD | ||||||
body_length | 164 | ||||||
author_reputation | 151,901,967,807,285 | ||||||
root_title | "Insert / Detach ViewRefs between multiple ViewContainerRefs " | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||
percent_hbd | 10,000 | ||||||
post_id | 26,619,047 | ||||||
net_rshares | 229,362,078 | ||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
azarus | 0 | 229,362,078 | 100% |
Oh there will be a lot from me for sure. I've been programming for almost 10 years now. I do have lots of code, libraries, frameworks, snippets and knowledge to share. I just couldn't afford the time until know. Thanks for letting me be here :)
author | azarus |
---|---|
permlink | re-netuoso-re-azarus-insert-detach-viewrefs-between-multiple-viewcontainerrefs-20180104t031036381z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-01-04 03:10:36 |
last_update | 2018-01-04 03:10:36 |
depth | 2 |
children | 0 |
last_payout | 2018-01-11 03:10:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 244 |
author_reputation | 4,239,423,105,752 |
root_title | "Insert / Detach ViewRefs between multiple ViewContainerRefs " |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 26,928,382 |
net_rshares | 0 |
### Hey @azarus I am @utopian-io. I have just upvoted you! #### Achievements - You have less than 500 followers. Just gave you a gift to help you succeed! - Seems like you contribute quite often. AMAZING! #### Suggestions - Contribute more often to get higher and higher rewards. I wish to see you often! - Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck! #### Get Noticed! - Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions! #### Community-Driven Witness! I am the first and only Steem Community-Driven Witness. <a href="https://discord.gg/zTrEMqB">Participate on Discord</a>. Lets GROW TOGETHER! - <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for my Witness With SteemConnect</a> - <a href="https://v2.steemconnect.com/sign/account-witness-proxy?proxy=utopian-io&approve=1">Proxy vote to Utopian Witness with SteemConnect</a> - Or vote/proxy on <a href="https://steemit.com/~witnesses">Steemit Witnesses</a> [](https://steemit.com/~witnesses) **Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x**
author | utopian-io |
---|---|
permlink | re-azarus-insert-detach-viewrefs-between-multiple-viewcontainerrefs-20180105t213839241z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"} |
created | 2018-01-05 21:38:39 |
last_update | 2018-01-05 21:38:39 |
depth | 1 |
children | 0 |
last_payout | 2018-01-12 21:38:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 1,504 |
author_reputation | 152,955,367,999,756 |
root_title | "Insert / Detach ViewRefs between multiple ViewContainerRefs " |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 27,375,918 |
net_rshares | 0 |
author | wehmoen |
---|---|
permlink | re-azarus-insert-detach-viewrefs-between-multiple-viewcontainerrefs-20180105t150435572z |
category | utopian-io |
json_metadata | {} |
created | 2018-01-05 15:04:36 |
last_update | 2020-06-03 07:02:06 |
depth | 1 |
children | 0 |
last_payout | 2018-01-12 15:04:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.104 HBD |
curator_payout_value | 0.031 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 1 |
author_reputation | 86,504,380,503,125 |
root_title | "Insert / Detach ViewRefs between multiple ViewContainerRefs " |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 27,302,807 |
net_rshares | 14,033,236,322 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
mkt | 0 | 14,033,236,322 | 25% |