AngularJS 1.4 --> Angular 9 migration [duplicate]

拈花ヽ惹草 提交于 2020-03-12 06:27:32

问题


I have decided to do a complete rewrite of the large scale application that I am working on since it is in AngularJS 1.4. I transferred over most of my HTML and CSS files and am now ready to create the TypeScript files.

Do I need to create a TypeScript file for every JavaScript file that is in the 1.4 version, or will there be fewer TypeScript files? At first, I assumed I would need the same amount of TypeScript files as there are JavaScript. But after researching it I find a lot of places that say "Make each page of your application one component". So this makes me think if I have 5 total pages on my application then I will only need 5 total TypeScript files. The original contains ~80 JavaScript files.


回答1:


Your plan is called the "big bang rewrite", it's very common, and it's a bad idea.

In most cases, it’s the Big Bang approach that wins the argument.

But by making it a Big Bang release, you’ve maximized the chances that you’ll be behind schedule when you get to the end, and you’ve therefore maximized the chances that you won’t spend enough time preparing. This results in a bad time for both you and your customers.

Unfortunately, perhaps due to something intrinsic in human nature, this scenario is a cliche for Big Rewrite projects.

— Chad Fowler: The Big Bang

One of the keys to a successful upgrade is to do it incrementally, by running the two frameworks side by side in the same application, and porting AngularJS components to Angular one by one. This makes it possible to upgrade even large and complex applications without disrupting other business, because the work can be done collaboratively and spread over a period of time. The upgrade module in Angular has been designed to make incremental upgrading seamless.

For more information, see

  • Angular Developer Guide - Upgrading from AngularJS
  • Migrating AngularJS to Angular 4,5 (with DEMO)
  • Running Angular and AngularJS frameworks side by side
  • AngularJS Developer Guide - Component-based application architecture
  • AngularJS 1.5+ Components do not support Watchers, what is the work around?



回答2:


The goal of making every page a component is to make it easy the use of routers.

It really depends of your application, if you have a portion that is used multiple times in the same page, you can make a component with inputs and ouputs and then you can mutualise your code.

So before you create a new component you have to ask yourself two questions

  1. Will i reuse this component in other pages ?

  2. Does this component need to be in a specific URL?



来源:https://stackoverflow.com/questions/60382892/angularjs-1-4-angular-9-migration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!