Code Monkey home page Code Monkey logo

angular2-es6-starter's Introduction

Angular 2 ESNext Starter

Dependency Status devDependency Status Build Status Code Climate Code Coverage

This repo stands as a starting point for those who try Angular 2 in Javascript. It shows techniques how easy development can be also without Typescript. It is a basic CRUD application with authentication, similar to the news site jslive.com. You can see the list of links, add and edit them after you signed in.

If you're looking for Angular 2 in Javascript without Gulp tasks and server side check out angular2-esnext-todomvc

If you're looking for Angular 2 in Typescript check out angular2-webpack-starter

  • Pure Javascript implementation.
  • Uses Babel to support class/parameter decorators.
  • Same language constructs can be used as in Typescript (types will be stripped).
  • Bundles files with Webpack.
  • Automates tasks with Gulp.
  • Automatically rebundles and refreshes the browser on changes.
  • Unit testing with Karma and Jasmine.
  • Code coverage for original ES6 code.
  • E2E testing with Protractor.
  • Includes deployment to Heroku.
  • Linting with ESlint based on Airbnb's styleguide.
  • Layout and namings based on the official Angular 2 style guide

Motivation

There are plenty of resources for starter packs and documentations on how to write your Angular 2 application in Typescript. The official documentation is only complete for Typescript and the parts which are also in Javascript are so few and in ES5 syntax which is little bit verbose compared to ES6. This is why i decided to make a starter pack to show that equivalent easy and viable solutions exist in Javascript.

It does not want to be by any means an against Typescript repository, just a choice for people, who like the loosely typed nature of Javascript or just feel overwhelmed by having to learn both Angular 2 and Typescript when trying out the new framework. By adding Flow types and using decorators wherever you can, it will be really easy to switch to Typescript by adding type definitions to the project (if you want to).

Concepts covered

  • Creating components with directives
  • Communication between child and parent components
  • Dependency injection for services
  • Change detection strategies
  • Using custom pipes in templates
  • Handling HTTP calls
  • Using observables
  • Routing
  • Authentication and restricting access to routes
  • Form handling
  • Using custom validators in forms
  • Internationalization ng2-translate not compatible with Angular 2 rc.0 for now

Quick Start

git clone https://github.com/blacksonic/angular2-esnext-starter.git
cd angular2-esnext-starter
npm install

gulp serve

It bundles the application, copies the static files and starts the webserver with Nodemon. The transpiled application will have two separate ES5 compatible files: vendor.js for vendor libraries, boot.js for application logic. Server side changes restart the server, client side changes rebundle the Angular 2 application and refresh the page with Livereload.

Note: The application needs at least Node 4+ installed.

Open it in your browser http://localhost:9000 and start coding your first Angular 2 application in Javascript!

Testing

gulp test

Runs tests with Karma and Jasmine. Uses a single entry point (setup.spec.js), which includes all the *.spec.js files and runs the tests inside them. The test files can be found in the client/app folder next to the source files.

Because a clean bundling with Webpack can take multiple seconds, it is not ideal for development to run a clean test run every time. Instead it can run continuously on your development machine.

gulp test-dev

To get a good overview of testing possibilities within Angular 2 read this article.

ES6 workarounds

No more is needed, code can be written as in Typescript!

Read about the details how it is implemented in this article.

Authentication

Authentication is solved by extending the default RouterOutlet and adding logic to it's activate method. This solution is preferred for now, because the @CanActivate router lifecycle decorator has no access to the application's dependency injection, only with workarounds. For a detailed explanation read this article.

Deployment (to Heroku)

It bundles the client application and copies static files and server files to the dist directory along with package.json. Then it can be commited to the desired location (for example Heroku).

gulp dist

cd dist
git init
git add -A .
git commit -m "Deploy #1" && echo Committed
git push -f [email protected]:angular2-es6-starter.git master

Check out the deployed version.

angular2-es6-starter's People

Contributors

leebrandt avatar leoyuholo avatar sonicoder86 avatar

Watchers

 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.