Title: '$locationShim': Not a valid '@angular/upgrade' application. · Issue #46211 · angular/angular · GitHub
Open Graph Title: '$locationShim': Not a valid '@angular/upgrade' application. · Issue #46211 · angular/angular
X Title: '$locationShim': Not a valid '@angular/upgrade' application. · Issue #46211 · angular/angular
Description: Description I'm getting issues implementing ngUpgrade according to the official docs. I am at the stage when everything works, except navigation from Angular 1 to Angular 13. It is not clear from the docs where this code should be put: a...
Open Graph Description: Description I'm getting issues implementing ngUpgrade according to the official docs. I am at the stage when everything works, except navigation from Angular 1 to Angular 13. It is not clear from t...
X Description: Description I'm getting issues implementing ngUpgrade according to the official docs. I am at the stage when everything works, except navigation from Angular 1 to Angular 13. It is not clear fr...
Opengraph URL: https://github.com/angular/angular/issues/46211
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"'$locationShim': Not a valid '@angular/upgrade' application.","articleBody":"### Description\n\nI'm getting issues implementing ngUpgrade according to the official docs.\r\nI am at the stage when everything works, except navigation from Angular 1 to Angular 13.\r\nIt is not clear from the docs where this code should be put:\r\n\r\n```\r\nangular.module('rxntBillingApp')\r\n .factory('$location', downgradeInjectable($locationShim));\r\n```\r\nI tried putting it before `app.bootstrap(el)` in LazyLoaderService, but this results in an error:\r\n\r\n> lazy-loader.service.ts:21 Error: Error while instantiating injectable '$locationShim': Not a valid '@angular/upgrade' application. Did you forget to downgrade an Angular module or include it in the AngularJS application?\r\n\r\nThis is a valid angular upgrade application because when this `$locationShim` downgrade is removed, everything works fine. The reason to introduce location shim is to unify routing, so that AngularJS application can route back to Angular 13 app.\r\n\r\nIt's not very clear from the docs, but I changed `this.upgrade.bootstrap` inside app.module.ts to bootstrap a regular AppComponent, which then has `\u003crouter-outlet>` and routes to Angular 13 test component or to AngularJS component which lazily loads all the static assets and performs the bootstrap.\r\n\r\n```ts\r\n// app-routing.module.ts\r\nexport const routes: Routes = [\r\n // Routes rendered by Angular\r\n { path: 'test-component', component: TestComponent },\r\n\r\n // AngularJS routes\r\n { path: '**', component: AngularJSComponent },\r\n];\r\n\r\n@NgModule({\r\n imports: [RouterModule.forRoot(routes)],\r\n exports: [RouterModule]\r\n})\r\nexport class AppRoutingModule { }\r\n```\r\n\r\n```ts\r\n// angular-js.component.ts\r\nexport class AngularJSComponent implements OnInit, OnDestroy {\r\n constructor(\r\n private lazyLoader: LazyLoaderService,\r\n private elRef: ElementRef\r\n ) {}\r\n\r\n ngOnInit() {\r\n this.lazyLoader.load(this.elRef.nativeElement);\r\n }\r\n\r\n ngOnDestroy() {\r\n this.lazyLoader.destroy();\r\n }\r\n}\r\n```\r\n\r\nAnd here is the code for `LazyLoaderService`, which is following the official example:\r\n\r\n```ts\r\nimport { Injectable } from '@angular/core';\r\nimport angular from 'angular';\r\nimport { downgradeInjectable } from '@angular/upgrade/static';\r\nimport { $locationShim } from '@angular/common/upgrade';\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\nexport class LazyLoaderService {\r\n private app: angular.auto.IInjectorService | undefined;\r\n\r\n load(el: HTMLElement): void {\r\n import(/* webpackChunkName: \"main.legacy\" */ '../../app/index').then(app => {\r\n try {\r\n angular.module('rxntBillingApp')\r\n .factory('$location', downgradeInjectable($locationShim)); // tried adding this code:\r\n \r\n this.app = app.bootstrap(el);\r\n } catch (e) {\r\n console.error(e);\r\n }\r\n });\r\n }\r\n\r\n destroy() {\r\n if (this.app) {\r\n this.app.get('$rootScope').$destroy();\r\n }\r\n }\r\n}\r\n```\r\n\r\napp.bootstrap code is as follows:\r\n\r\n```ts\r\nexport function bootstrap(el: HTMLElement) {\r\n return angular.bootstrap(el, ['rxntBillingApp']); \r\n}\r\n```\r\n\r\nPlease advise if you can see anything wrong with the above implementation.\n\n### What is the affected URL?\n\nhttps://angular.io/guide/upgrade#using-the-unified-angular-location-service\n\n### Please provide the steps to reproduce the issue\n\n_No response_\n\n### Please provide the expected behavior vs the actual behavior you encountered\n\n_No response_\n\n### Please provide a screenshot if possible\n\n_No response_\n\n### Please provide the exception or error you saw\n\n_No response_\n\n### Is this a browser-specific issue? If so, please specify the device, browser, and version.\n\n_No response_","author":{"url":"https://github.com/vzakharov-rxnt","@type":"Person","name":"vzakharov-rxnt"},"datePublished":"2022-06-01T15:04:52Z","url":"https://github.com/angular/angular/issues/46211"}
| 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:fb24035e-8e35-65e9-be37-54daaf7affa1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D15E:7A60E:BECC05:F7818D:6B00EED2 |
| html-safe-nonce | e8131d7a6e7e299919153efbf9375fe420e3064e5be8d1db5b364c80472e33ff |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTVFOjdBNjBFOkJFQ0MwNTpGNzgxOEQ6NkIwMEVFRDIiLCJ2aXNpdG9yX2lkIjoiNzIwODI5ODYxMTcyODI0ODUzMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6fe75af851180bd944821fc81a491e9d3e0d965ffce5bc9a879096af052a8b8f |
| hovercard-subject-tag | issue:1256234813 |
| 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/46211/issue_layout |
| twitter:image | https://opengraph.githubassets.com/27fc0de250cca6649ca14ac80835a804b9661754cbb93dd7bbac21090f4756c2/angular/angular/issues/46211 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/27fc0de250cca6649ca14ac80835a804b9661754cbb93dd7bbac21090f4756c2/angular/angular/issues/46211 |
| og:image:alt | Description I'm getting issues implementing ngUpgrade according to the official docs. I am at the stage when everything works, except navigation from Angular 1 to Angular 13. It is not clear from t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | vzakharov-rxnt |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width