Skip to content

This repository will provide you access to angular 2 based implementation of an E-Commerce Site. This will also serve as one place to experiment and learn new angular 2 related implementations, tricks, best practices. You are welcome to peek in code, fork it, discuss on it. Lets learn while coding real applications.

License

Notifications You must be signed in to change notification settings

mutanttech/Angular2-ECommerce-Site-Sample

Repository files navigation

Angular-2-ECommerce-Site-Sample

This repository will provide you access to angular 2 based implementation of an E-Commerce Site. This will also serve as one place to experiment and learn new angular 2 related implementations, tricks, best practices. You are welcome to peek in code, fork it, discuss on it. Lets learn while coding real applications.

The design of the app is not super awesome because the focus is on learning how to create a working Angular 2 app.

So far in few commits, I have used/learnt following concepts:

  1. Angular BootStrapping
  2. Project Structure and File Organisation
  3. Creating Components
  4. Creating Services
  5. Communication Between Components
  6. Passing Data through Shared Services
  7. Implementing Observables using RxJS
  8. Routing
  9. Getting comfortable with using TypeScript
  10. Loading Indicator on Ajax Call implemented with Observable
  11. Data saved and fetched using mLab (A leading free/paid cloud based MongoDB service provider)

Prerequisites

Node.js and npm are essential to Angular development.

Get it now if it's not already installed on your machine.

Verify that you are running at least node v4.x.x and npm 3.x.x by running node -v and npm -v in a terminal/console window. Older versions produce errors.

I recommend nvm for managing multiple versions of node and npm.

Create a new project based on this sample

Clone this repo into new project folder (e.g., my-proj).

git clone https://github.com/mutanttech/Angular2-ECommerce-Site-Sample  my-proj
cd my-proj

Delete non-essential files (optional)

You can quickly delete the non-essential files that concern testing and QuickStart repository maintenance (including all git-related artifacts such as the .git folder and .gitignore!) by entering the following commands while in the project folder:

OS/X (bash)
xargs rm -rf < non-essential-files.osx.txt
rm src/app/*.spec*.ts
rm non-essential-files.osx.txt
Windows
for /f %i in (non-essential-files.txt) do del %i /F /S /Q
rd .git /s /q
rd e2e /s /q

Install Python 2.7.x version

During installing npm packages I found that Python was being required at some point, the installation process looks for C:\Python27. So you need to install the Python 2.7.x. You can get it from here

Install npm packages

See npm and nvm version notes above

Install the npm packages described in the package.json and verify that it works:

npm install
npm start

Doesn't work in Bash for Windows which does not support servers as of January, 2017.

The npm start command first compiles the application, then simultaneously re-compiles and runs the lite-server. Both the compiler and the server watch for file changes.

Shut it down manually with Ctrl-C.

You're ready to write your application.

npm scripts

I've captured many of the most useful commands in npm scripts defined in the package.json:

  • npm start - runs the compiler and a server at the same time, both in "watch mode".
  • npm run build - runs the TypeScript compiler once.
  • npm run build:w - runs the TypeScript compiler in watch mode; the process keeps running, awaiting changes to TypeScript files and re-compiling when it sees them.
  • npm run serve - runs the lite-server, a light-weight, static file server, written and maintained by John Papa and Christopher Martin with excellent support for Angular apps that use routing.

Here are the test related scripts:

  • npm test - compiles, runs and watches the karma unit tests
  • npm run e2e - compiles and run protractor e2e tests, written in Typescript (*e2e-spec.ts)

Testing

The QuickStart documentation doesn't discuss testing. This repo adds both karma/jasmine unit test and protractor end-to-end testing support.

These tools are configured for specific conventions described below.

It is unwise and rarely possible to run the application, the unit tests, and the e2e tests at the same time. I recommend that you shut down one before starting another.

Unit Tests

TypeScript unit-tests are usually in the src/app folder. Their filenames must end in .spec.ts.

Look for the example src/app/app.component.spec.ts. Add more .spec.ts files as you wish; we configured karma to find them.

Run it with npm test

That command first compiles the application, then simultaneously re-compiles and runs the karma test-runner. Both the compiler and the karma watch for (different) file changes.

Shut it down manually with Ctrl-C.

Test-runner output appears in the terminal window. We can update our app and our tests in real-time, keeping a weather eye on the console for broken tests. Karma is occasionally confused and it is often necessary to shut down its browser or even shut the command down (Ctrl-C) and restart it. No worries; it's pretty quick.

End-to-end (E2E) Tests

E2E tests are in the e2e directory, side by side with the src folder. Their filenames must end in .e2e-spec.ts.

Look for the example e2e/app.e2e-spec.ts. Add more .e2e-spec.js files as you wish (although one usually suffices for small projects); we configured Protractor to find them.

Thereafter, run them with npm run e2e.

That command first compiles, then simultaneously starts the lite-server at localhost:8080 and launches Protractor.

The pass/fail test results appear at the bottom of the terminal window. A custom reporter (see protractor.config.js) generates a ./_test-output/protractor-results.txt file which is easier to read; this file is excluded from source control.

Shut it down manually with Ctrl-C.

About

This repository will provide you access to angular 2 based implementation of an E-Commerce Site. This will also serve as one place to experiment and learn new angular 2 related implementations, tricks, best practices. You are welcome to peek in code, fork it, discuss on it. Lets learn while coding real applications.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published