際際滷

際際滷Share a Scribd company logo
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
import { downgradeModule } from '@angular/upgrade/static';
import { ng1App } from './ng1_app';
import { Ng2AppModule } from './ng2_app_module';
const ng2Module = downgradeModule(Ng2AppModule);
bootstrap(document.body, [ng1App.name, ng2Module, ...]);
Downgraded ng2 components
@Component({
selector: 'ng2-router-root',
template: '<router-outlet></router-outlet>',
})
export class Ng2RouterRoot {}
@NgModule({
declarations: [ Ng2RouterRoot ],
entryComponents: [ Ng2RouterRoot ],
exports: [ Ng2RouterRoot ],
})
export class Ng2RouterRootNg2Module {}
export const routerRootModule = angular
.module('routerRootModule', [])
.directive('ng2RouterRoot', downgradeComponent({
component: Ng2RouterRoot,
outputs: ['ng2RouterRoot'],
propagateDigest: false
}) as ng.IDirectiveFactory);
<ng2-router-root></ng2-router-root>
angular.module('NavWidgetNg1Module', [])
.directive(
'NavWidget', downgradeComponent({
component: NavWidget,
inputs: ['property']
}) as ng.IDirectiveFactory);
<shell-widget property=true></shell-widget>
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
@NgModule({
...
providers: [
LocationSynchronizer, {
provide: UrlSerializer,
useClass: CustomUrlSerializer
},
]
})
export class Ng2AppModule {}
const NG2_PATHS: Array<string|RegExp> = [
'/product1',
'/product2/path',
'/feature2/[^/]+/subpath',
];
function isNg2(path: string) {
return NG2_PATHS.some(
(entry) => (entry instanceof RegExp) ?
entry.test(path) : path.startsWith(entry);
}
$routeProvider.otherwise({
controller: UnmappedPathController,
controllerAs: 'ctrl',
template: `<div ng-if=ctrl.show404> Not found :-( </div>`,
});
class UnmappedPathController {
show404 = false;
constructor(private readonly $location) {
if (isNg2Path($location.url())) return;
this.show404 = true;
}
}
export const ROUTES: Routes = [
{path: '/section1', load: 'section1_module'}, // etc.
{matcher: ng1UrlMatcher, component: Ng1Component},
{path: '**', component: PageNotFound},
];
export function ng1UrlMatcher(
url: UrlSegment[], group: UrlSegmentGroup): UrlMatchResult {
return {consumed: !isNg2Path(group.toString()) ? [] : url};
}
@Component({template: ''})
export class Ng1Component {}
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
return this.myResourceDao
.get({id: this.route.params.id})
.$promise.then((response: Response) => response.items)
.then(items: Item[]) => items.map(i => ({
id: i.id, name: i.fullName
})));
return this.getResourceObs(this.route.params.id)
.map((items: Item[]) => { id: i.id, name: i.fullName
});
beforeEach(() => {
superProviders: [{
provide: MyResourceService,
useValue: jasmine.createSpyObj(
'myResourceService', ['getItem']),
}],
});
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
prefixed naming
view encapsulation
container
class
prefixed naming
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
UI Components
UI Tests
Product UI
Testing
Framework
Business Logic
Components
/Services
Testing APIs
Styling Utilities
Template APIs
Component APIs
UI Components
UI Tests
Product UI
Testing
Framework
Business Logic
Components
/Services
Testing APIs
Styling Utilities
Template APIs
Component APIs
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
 Translating template syntax from AngularJS to Angular
UI Components
UI Tests
Product UI
Testing
Framework
Business Logic
Components
/Services
Testing APIs
Styling Utilities
Template APIs
Component APIs
<md-input-container>
<label>State</label>
<md-select
ng-model="ctrl.userState">
<md-option
ng-repeat="state in
ctrl.states"
ng-value="state.abbrev">
{{state.abbrev}}
</md-option>
</md-select>
</md-input-container>
<mat-form-field>
<mat-select placeholder="State"
[(ngModel)]="userState">
<mat-option
*ngFor="let state of
states"
[value]="state.abbrev">
{{state.abbrev}}
</mat-option>
</mat-select>
</mat-form-field>
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular
Migrating a 1M+ LOC project from AngularJS to Angular

More Related Content

Migrating a 1M+ LOC project from AngularJS to Angular