How much trouble is it to change from Angular 1 to Angular 5?

以下是 Aaron Martin-Colby 在 Quora 上的回答。 转过来的原因是:这个问题问的人很多,Aaron 回答阅读量最高,5.9K ,点赞数也最高。

0_1518396802405_深度截图_选择区域_20180212085317.png

A lot.

The Angular team initially hoped to provide tools to aid in the transition from AngularJS to Angular, but that never came to fruition. You are on your own, where basically you have to map your stuff over.

The more inside AngularJS your app was, the easier it should be. But if you were mixing standard JQuery-style DOM interactions with your AngularJS code, your transition is going to be a nightmare. The DOM no longer exists in Angular 2. It is a product. Even worse if you were delivering partially built pages from your middleware, such as .NET, and then building on top of those with AngularJS on the client. That means you will need to move logic from your middleware onto your client. Good luck with that.

Changing from AngularJS to Angular is just as hard as changing to any other framework. For apps that were already modular, it’s easier, but the more monolithic your app gets, the harder the transition. I do not envy your position.

For help with the transition, Rangle has some good videos.

Upgrading Your Angular 1.x App to Angular 2.0

Also

How to Start Using Angular 2.0 with Your Angular 1.0 Code Base

And finally

Upgrading Angular apps using ngUpgrade

You’ll notice how all of those articles are old. Closing in on two years old for the Rangle videos. That’s because upgrading is something that pretty much everyone gave up on while Angular was still officially on beta. Really, the only way forward is a complete, ground-up rewrite. These resources are good for positioning yourself on the scale of difficulty, but the end result is basically the same:

You’re going to be writing a lot of code.

As such, take this opportunity to be sure you want Angular. This moment, this moment of decision, is a moment in which thousands of teams all over the world found themselves starting with the announcement that Angular was going to be an utterly breaking change from AngularJS. It is also the moment where a majority of them made the decision to move to React, which is why React will, within the year, become the most widely deployed front-end toolset in North America and Europe. Angular shot itself in the foot.

I’m not saying you shouldn’t use Angular, I’m just saying that, since the transition is so intensive, that you should not stick with Angular because you think it will save time. It will not. Choose the best framework instead of sticking blindly with Angular.

Aaron 说了一大堆,还给了很多资源链接,他想表达的意思中文简述如下:

整体表达的意思是:从 Angular 1 升级到 Angular 5 很烦,就是重写。

  • 官方曾经搞了一个工具来帮助升级,但是并没有什么卵用。
  • 如果你在写 AngularJS 1.x 项目的时候混用了 jQuery,升级就更难了,原因你懂的。
  • Angular 团队的升级策略搞死了自己,也直接导致了在欧美的使用量大幅度下降,让 React 有了机会。
  • 别老死盯着 Angular 不放了,尝试一下其它框架吧。

原文在此:https://www.quora.com/How-much-trouble-is-it-to-change-from-Angular-1-to-Angular-5