GithubHelp home page GithubHelp logo

agezfrederic / angular2-migration-sample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from emmanueldemey/angular2-migration-sample

0.0 2.0 0.0 230 KB

License: MIT License

JavaScript 61.07% HTML 26.36% TypeScript 12.57%

angular2-migration-sample's Introduction

This demo has been used for many conferences :

  • Technozaure (25th of September, Zenika Nord)
  • Chti JUG (29th of September, Lille)
  • Kaiz'n Day (8th of October, Paris)

How to do the migration from an AngularJS 1 application into Angular2

The main goal of this project is to describe how can migrate an AngularJS 1 application into Angular2. Some new features will be added in the future, in order to explain how to migrate everything from one version to the other.

Define one component per file (step1)

One of the best practice when developing AngularJS application, is to define one AngularJS component (service, controller, directive, filter) per file. The first task we have to do with this simple appication is to move all AngularJS into a specific file, and import these files in the index.html file.

We will also define a specific module for each component we will implement : brewery.directive, brewery.service and brewery.filter

Use ControllerAs and bindToController feature (step2)

In Angular2, will use directly JavaScript Object, in which we will add properties/functions thanks to the this keyword. In AngularJS 1 application, we can do the same kind of thing thanks to the controllerAs and bindToController features.

Use the Component First Pattern (step3)

In Angular2, everything is component, even the main element of the application. We can start using the same pattern in AngularJS 1. We just need to create a new component, let's say app, with a specific controller similar to the previous BreweryCtrl controller.

Declare services with the service method (step4)

One other small tip, when creating services, we should :

  • first we always the same method : service/factory in order to have the syntax everywhere
  • Prefer the use of service, because we will manipulate directly the service object by adding properties/methods to the this object like in Angular 2

At the same time, you shoule only use the simple DI sytax (via function parameters) and use the ngAnnotate plugin in order to manage issues after minification.

Right now our AngularJS 1 application is ready for the migration. (step5)

We will describe in this part we can convert all our AngularJS 1 components into Angular 2.

Generate a new Angular2 thanks to angular-cli

ng new ng2

Copy and Rename all files with the .ts extension in this new project

Update the implentation of the Service

Update the implentation of the Filter

Update the implentation of the Beer Component

Update the implentation of the App Component

angular2-migration-sample's People

Contributors

emmanueldemey avatar gdrouet avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.