Skip to content

Commit a434835

Browse files
devversionalxhub
authored andcommitted
fix(upgrade): allow for downgraded components to work with component-router (#50871)
In the past, we had an implementation of the "Angular 2" router that also worked with AngularJS. Published as `@angular/router`. We continued to expose that router implementation in G3 and some applications still use it. Now, when upgrading, they are seeing issues where the router throws because it cannot find a route config/ or `$canActivate` on the controller- simply because there is no `controller` function for downgraded components. We can fix this and unblock the update by simply ensuring a controller function is defined. PR Close #50871
1 parent 4ba5850 commit a434835

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/upgrade/src/common/src/downgrade_component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ export function downgradeComponent(info: {
9898
restrict: 'E',
9999
terminal: true,
100100
require: [REQUIRE_INJECTOR, REQUIRE_NG_MODEL],
101+
// Controller needs to be set so that `angular-component-router.js` (from beta Angular 2)
102+
// configuration properties can be made available. See:
103+
// See G3: javascript/angular2/angular1_router_lib.js
104+
// https://github.com/angular/angular.js/blob/47bf11ee94664367a26ed8c91b9b586d3dd420f5/src/ng/compile.js#L1670-L1691.
105+
controller: function() {},
101106
link: (scope: IScope, element: IAugmentedJQuery, attrs: IAttributes, required: any[]) => {
102107
// We might have to compile the contents asynchronously, because this might have been
103108
// triggered by `UpgradeNg1ComponentAdapterBuilder`, before the Angular templates have

0 commit comments

Comments
 (0)