Coder Social home page Coder Social logo

cdoremus / state-geo-angular Goto Github PK

View Code? Open in Web Editor NEW
21.0 6.0 2.0 2.43 MB

Example of an AngularJS 1 app designed to be easy to upgrade to Angular 2 (in Angular2.0 branch)

JavaScript 84.53% HTML 6.90% CSS 8.57%
angularjs angular karma protractor webpack

state-geo-angular's Introduction

state-geo: Test your knowledge of the US states

Build Status

Note: This branch holds the Angular 1.5 version of this application in the master (this) branch. The Angular 2.0 version is in the angular2.0 branch.

The programming is done as an AngularJS 1 app using a component-based directive architecture similar to Angular 2.0 to make it easy to upgrade to the new version. This was accomplished by following these guidelines:

  • ES6/2015 is used throughout since Angular 2 is written in the new JavaScript version. Babel is used to transpile the code to ES5.
  • AngularJS directives are created using the component() method instead of the directive() method.
  • All of the directive's tag attribute values are locally scoped properties or event bindings of the directive's controller. These attributes are also used in Angular 2 templates with their values bound to the Angular 2 component using @Input (for properties) or @Output (for events).
  • Each directive's controller is implemented in a separate ES6/2015 class. They will become the Angular 2 component class when the app is upgraded.
  • The AngularJS directive's controller uses the controllerAs property (or the default $ctrl) as the controller's alias. This prevents use of $scope in the template since is not available in Angular 2. The AngularJS app does not use $scope elsewhere too.
  • Replaced $watch() calls in AngularJS with RxJS Observable subscriptions since $watch is missing in Angular 2.
  • AngularJS services are implemented as ES6/2015 classes. They will port directly to Angular 2.
  • Standalone Angular controllers are NOT used in the app since they are dropped in Angular 2. Instead, the controller code is encapsulated in a component directive that functions as a container.

An example of how to to upgrade a ES6/2015 AngularJS 1.5 component-based directive to Angular 2.0. Analogous code blocks are colored. TranslatingNg1ToNg2

The build system for this application uses gulp with webpack (and babel). Stylus is used as the CSS preprocessor with Jeet to aid layout. If you want to run the program locally, follow the following steps:

# clone this repo
git clone https://github.com/cdoremus/state-geo-angular.git

# change directory to the repo
cd state-geo-angular

# make sure you have the global npm packages installed
npm install -g gulp karma protractor

# install the repo's dependencues
npm install

# build the app
gulp

# start the server in a separate window
gulp serve

The application can then be accessed by browsing to http://localhost:4500/.

Unit and end-to-end functional tests can be run using the following commands:

#Run unit tests run using Karma
npm tests

#Run end-to-end functional tests using Protractor
npm run e2e

The templates folder contains templates for new components built inside of a new folder under client/app. They can be created with this command: gulp component --name newComponentName

This project builds a bundle.js that is put in a destination folder (dist). The application can also be configured to use a RESTful Java web service and MongoDB (see state-geo-server-spring).

A running version of the application can be found at http://cdoremus.github.io/state-geo-quiz/.

Screenshot of Adjacent States Quiz with Erroneous Results and Components outlined on the screen: AdjacentQuizResultsScreenshotComponents

Screenshot of Adjacent States Quiz with Correct Results: AdjacentQuizResultsSuccessScreenshot

Screenshot of State Capitals Quiz with Correct Results: StateCapitalsQuizResultsScreenshot

state-geo-angular's People

Contributors

cdoremus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

msicsic darocha

state-geo-angular's Issues

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.