Coder Social home page Coder Social logo

angular-2-refactor's Introduction

Angular 2 Refactoring Lab

Set Up

First, fork and clone this repo.

In the starter-code folder, you will need to install your bower dependencies.

Then, start your simpleHTTPServer with python to see a fully functioning Angular app. Cool, right? But not very modern.

Throughout this lab, we will slowly turn our Angular 1 app into an Angular 2 app, using our good friend, refactoring.

If you get stuck, you should use this guide on the Angular 1 and Angular 2 code differences, as well as a healthy amount of Google, and a little bit of help from your neighbors.

Set Up Round Two

Follow this guide to set up a local Angular 2 hello world. The quickstart folder you create for this app should be at the same level as starter-code.

Before you move on to the next step, take a quick look at the package.json inside quickstart. Look at all those @angulars. Those will come into play very soon.

Also, look at the TypeScript files mentioned in the tutorial and look at index.html.

Change the name field in app.component.ts, and see it update. Notice how you don't even have to refresh the page. Cool, right?

Getting Started

The amount of files in this project is a little daunting, but you only need to worry about a few files. Start small, and gradually add in new features from starter-code into quickstart.

  • First, you should probably create an HTML template that is referenced by Url rather than written as a string. Create a new templates folder and put it inside app. How would you replace the hardcoded template with this file? (Hint: It's basically the same as for ngRoute in Angular.)
  • Now, the fun part. Slowly add the pieces of your Angular 1 app from starter-code/index.html to app/templates/cartoon.html and from starter-code/client.js to app/app.component.ts. You can find the code you'll need in this guide.
  • In addition to app.component.ts and cartoon.html, you may also need to change app.module.ts as you go through this refactoring.
  • Once you have all the HTML in cartoon.html, use the new Angular 2 styleUrls method to include cartoonStyle.css.
  • Finally, see if you can get MyFactory injected into your component. Note that there are a lot of ways to do this, and it is quite tricky. Hint: exporting and importing a class is a good place to start.

Deliverable

When you are finished, you should be able to look at your Angular 2 and Angular 1 apps side-by-side and see no major differences. Feel free to rename your quickstart folder to something more useful like angular-2 or angular-cartoon.

angular-2-refactor's People

Contributors

zebgirouard avatar

Watchers

James Cloos 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.