Don't jump into this blindly!
Where are you now?
Where do you want to be?
Set yourself up for success
Get the latest version of AngularJS
They are very syntactically similar so can help with the upgrade.
angular.module('veryComplicatedApp')
.component('appDoSomeMath', function () {
return {
template: '{{ $ctrl.num }} + 1 = {{ $ctrl.addedNum }}
',
bindings: {
num: '@'
},
controller: doSomeMath
};
function doSomeMath () {
this.$onInit = function () {
this.addedNum = this.num + 1;
}
}
});
@Component({
selector: 'app-do-some-math',
template: '{{ num }} + 1 = {{ addedNum }}
'
})
export class DoSomeMathComponent {
@input() numberToAddOneTo: Number;
ngOnInit () {
this.addedNumber = this.numberToAddOneTo + 1;
}
}
This will be super-duper complicated
You have no idea what I am about to do.Consider the "Planning" step and figure out your build process
If you have no idea where to start with this, consider this exercise: "If I just mass-converted to typescript, where could I fit the typescript compilation step in there with what I have?"Webpack is pretty "in" right now, and for good reason.
It's also what the Angular CLI uses, so keep that in mind if you would like to eventually start using it.Incrementally upgrade your app by simultaneously loading both frameworks.
Upgrade: AngularJS to Angular
e.g. an AngularJS service consumed by an Angular component. You are "upgrading" the AngularJS service to be compatible with the Angular consumer.Downgrade: Angular to AngularJS
e.g. an Angular component within an AngularJS module. You are "downgrading" the Angular component to be compatible with the AngularJS module.
@Component({
selector: 'app-do-some-math',
template: '{{ num }} + 1 = {{ addedNum }}
'
})
export class DoSomeMathComponent {
@input() numberToAddOneTo: Number;
ngOnInit () {
this.addedNumber = this.numberToAddOneTo + 1;
}
}
///////////////////
import { DoSomeMathComponent } from './do-some-math.component';
import { downgradeComponent } from '@angular/upgrade/static';
angular.module('veryComplicatedApp')
.component(
'appDoSomeMath',
downgradeComponent({ component: DoSomeMathComponent }) as angular.IDirectiveFactory
);
Remember to add the component to your module's declarations array.
In the spirit of BrieBug CEO Jessie's original "Transitioning to Angular 2" series, we will go over a few more things in the...
Where are we now?
Where do we want to be?
A look at an in-progress upgrade
Gotchas