Onza Onza - 10 months ago 65
AngularJS Question

Migrate to angular 2

I got a legacy application written in angular 1 which needs to be fixed.

I'm required to write unit tests in order to do any modifications to the app, so my questions are:

  1. Is there a framework you can use to write unit tests that works in angular 1 and 2 without having to modify them (or not too much).

  2. How do I migrate the thing? without having to do much work, administration says the it should kept itself on angular 1, but I find angular 1 to be not as good as angular two (probably because 2 reminds me of react more, and I'm a react developer). Thing is that every single page has a module, a controller and a view (yes every single page), there are no reusable components whatsoever, but it uses history API routing (in some tangled way), if so how could I change page by page to use angular 2 instead of 1?

eg. module

.config(function ($stateProvider) {
.state('cats', {
url: '/cats',
templateUrl: 'cats/cats.html',
controller: 'CatsCtrl',
authenticate: true


.controller('CatsCtrl', function ($scope, $http, $firebaseObject) {
$scope.catNumber = 10;

//Main spagetthi here... D:


<div>we got {{catNumber}} cats</div>

I need some rough ideas, no need to be specific; I have to figure out things myself later anyway.

Answer Source

There's no such thing as universal unit tests, you will need to write different ones, but it doesn't mean that you can't copy or re-use some of the logic. The best thing for you to do, is following the official migration guide. You can have the two different versions working alongside. But the hardest part will be setting up Webpack and all the tooling, if you are not used to that.

My advice? Don't try to fix what isn't broken. Angular 1 is being used since 2009, a lot has changed since then, but it's still a good framework. If the admnistration is not willing to move to Angular 2 and you don't have their support, just keep doing Angular 1.

Because with this migration you are going to stumble upon a lot of difficulties, you will have to learn Angular 2, Webpack, Typescript and although you could go for Angular without typescript, you won't find as much as documentation. You will also have to make the two frameworks work alongside and re write the unit tests. Just think twice before jumping into this migration.