Title: Component lifecycles differs on nativescript-angular and angular2 on web. · Issue #374 · NativeScript/nativescript-angular · GitHub
Open Graph Title: Component lifecycles differs on nativescript-angular and angular2 on web. · Issue #374 · NativeScript/nativescript-angular
X Title: Component lifecycles differs on nativescript-angular and angular2 on web. · Issue #374 · NativeScript/nativescript-angular
Description: I ran into this problem and I'll try to explain it here. With nativescript-angular the lifecycle hook ngOnDestroy isn't called when we navigate away from a page as it would be on web. Navigating back reuses the old component with natives...
Open Graph Description: I ran into this problem and I'll try to explain it here. With nativescript-angular the lifecycle hook ngOnDestroy isn't called when we navigate away from a page as it would be on web. Navigating ba...
X Description: I ran into this problem and I'll try to explain it here. With nativescript-angular the lifecycle hook ngOnDestroy isn't called when we navigate away from a page as it would be on web. Navig...
Opengraph URL: https://github.com/NativeScript/nativescript-angular/issues/374
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Component lifecycles differs on nativescript-angular and angular2 on web.","articleBody":"I ran into this problem and I'll try to explain it here.\n\nWith `nativescript-angular` the lifecycle hook `ngOnDestroy` isn't called when we navigate away from a page as it would be on web. Navigating back reuses the old component with `nativescript-angular` but a new instance is created on web.\n\nI've based an example on Nathan Walker's `angular2-seed-advanced`:\nhttps://github.com/m-abs/angular2-seed-advanced/tree/ngondestroy-not-triggered\n\nI've two component for my routes:\n[HomeComponent](https://github.com/m-abs/angular2-seed-advanced/blob/ngondestroy-not-triggered/src/client/app/components/about/about.component.ts) \n[AboutComponent](https://github.com/m-abs/angular2-seed-advanced/blob/ngondestroy-not-triggered/src/client/app/components/home/home.component.ts)\n\nEach component have a `instanceNo`, so we can identify multiple instances of the component.\n\n| Action | Web | TNS |\n| --- | --- | --- |\n| Launch application | HomeComponent\u003c1\u003e.ngOnInit() is called | HomeComponent\u003c1\u003e.ngOnInit() is called |\n| Click on 'ABOUT' | HomeComponent\u003c1\u003e.ngOnDestroy() followed by AboutComponent\u003c1\u003e.ngOnInit() | AboutComponent\u003c1\u003e.ngOnInit() |\n| Click on 'HOME' | AboutComponent\u003c1\u003e.ngOnDestroy() followed by HomeComponent\u003c2\u003e.ngOnInit() | HomeComponent\u003c2\u003e.ngOnInit() |\n| Click back | HomeComponent\u003c2\u003e.ngOnDestroy() followed by AboutComponent\u003c2\u003e.ngOnInit() | HomeComponent\u003c2\u003e.ngOnDestroy() |\n| Click back again | AboutComponent\u003c2\u003e.ngOnDestroy() followed by HomeComponent\u003c3\u003e.ngOnInit() | AboutComponent\u003c1\u003e.ngOnDestroy() |\n\nAs you can see the two behaves very differently.\n## On web:\n- Navigate to a new page, the current component is destroyed and a new is created.\n- Navigating hitting back, the current component is destroyed and a new is created.\n## With nativescript-angular:\n- Navigate to a new page, creates the new component but leaves the current component as is.\n- Navigating hitting back, the current component is destroyed and the old component is reused.\n\nIf you want to try for yourself, checkout my branch `ngondestroy-not-triggered` and run:\n## For web:\n\n``` bash\nnpm run start \n```\n## For nativescript-angular with android:\n\n``` bash\nnpm run start.livesync.android\n```\n\nShouldn't the two behave the same?\nSo components are destroyed when we navigate from a page and (re)created when we navigate to the page?\n","author":{"url":"https://github.com/m-abs","@type":"Person","name":"m-abs"},"datePublished":"2016-07-27T23:52:46.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":30},"url":"https://github.com/374/nativescript-angular/issues/374"}
| 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:95554203-7ddd-665b-652e-aa075a716ff8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BCE8:140E58:5015136:67BB1AD:6975175E |
| html-safe-nonce | ef8294763ed84f587bb667416938e4c996acf60759d39f6ddeda1a65d2edf2c0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0U4OjE0MEU1ODo1MDE1MTM2OjY3QkIxQUQ6Njk3NTE3NUUiLCJ2aXNpdG9yX2lkIjoiMTI1NzE4Nzc5MDMxMTIwMDYwNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c7072d1a53870b156f7a321db7d9e0147a1f16a99024dc895a132ae2f6ecfa01 |
| hovercard-subject-tag | issue:167983236 |
| 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/NativeScript/nativescript-angular/374/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8825e3686c3a3004f6f8ab6c30a8d0ad55cbf8271d79c11c324b55982e74217a/NativeScript/nativescript-angular/issues/374 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8825e3686c3a3004f6f8ab6c30a8d0ad55cbf8271d79c11c324b55982e74217a/NativeScript/nativescript-angular/issues/374 |
| og:image:alt | I ran into this problem and I'll try to explain it here. With nativescript-angular the lifecycle hook ngOnDestroy isn't called when we navigate away from a page as it would be on web. Navigating ba... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | m-abs |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4a4bf5f4e28041a9d2e5c107d7d20b78b4294ba261cab243b28167c16a623a1f |
| turbo-cache-control | no-preview |
| go-import | github.com/NativeScript/nativescript-angular git https://github.com/NativeScript/nativescript-angular.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 35951404 |
| octolytics-dimension-repository_nwo | NativeScript/nativescript-angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 35951404 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/nativescript-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 | 488b30e96dfd057fbbe44c6665ccbc030b729dde |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width