问题
I'm not looking for an opinion - just a solid migration strategy.
We started to design a new project that designated to be built with Angular as each of our previous, the importance of this project is very high and it's going to live and maintained for at least 3-4 years.
Angular 2.0 is coming in the end of 2015 and it seems like everything is about to change, $scope is out, directives are out and the whole DI concept is about to change.
- Is there a migration path/strategy to be considered in the next few months?
- If we built the project using 1.x, what action do we need to take during development to ensure a clean migration?
- Are those 2 versions can be considered as 2 different framework? (Yes means Angular 1.x will continued to be supported and evolved by google)
回答1:
At the 2015 ng-Conf, the Angular team discussed initial concepts for this. Important things to note:
- You will be able to mix and match Angular 1 and Angular 2 modules so that you can incrementally move your app to Angular 2.
- Angular 2 will be written using TypeScript/ES7 so it may help you to use those languages and transpile them to ES5 for your current app. While you can use ES5 in Angular 2, there are things like class structures and annotations/decorators that may make working with Angular 2 easier.
- Migration instructions will be publish after Google has gone through the work of migrating one of it's internal applications. Others are likely to add their input as Angular 2 becomes more stable.
For more information from ng-Conf see the following videos:
- Day 1 Keynote
- Angular 1.3 meets Angular 2.0
回答2:
The latest blog post as of today from the Angular devs will give you a nice step-by-step process. The key will be to use the new ng-upgrade libraries. Here are the steps directly from the blog post (with link below):
- Include the Angular 2 and ng-upgrade libraries with your existing application
Pick a component which you would like to migrate
- Edit an Angular 1 directive's template to conform to Angular 2 syntax
- Convert the directive's controller/linking function into Angular 2 syntax/semantics
- Use ng-upgrade to export the directive (now a Component) as an Angular 1 component (this is needed if you wish to call the new Angular 2 component from an Angular 1 template)
Pick a service which you would would like to migrate
- a. Most services should require minimal to no change.
- b. Configure the service in Angular 2
- c. (optionally) re-export the service into Angular 1 using ng-upgrade if it's still used by other parts of your Angular 1 code.
- Repeat doing step #2 and #3 in an order convenient for your application development
- Once no more services/components need to be converted drop the top level Angular 1 bootstrap and replace with Angular 2 bootstrap.
Angular 1 and Angular 2 Coexistence
Good luck!
来源:https://stackoverflow.com/questions/27441268/angular-2-0-migration-path-from-angular-1-x