This repository contains the sample code for an Angular 4 update to Front-End Frameworks: AngularJS, a three-part series in James Shore's Let's Code: Test-Driven JavaScript screencast. Let's Code: Test-Driven JavaScript is a screencast series focused on rigorous, professional JavaScript development.
Those episodes were an exploration and review of the AngularJS "1" framework for building web applications. This repository updates the application built in that series to Angular "2". It demonstrates several concepts:
- Sample application. The sample application code can be found in
src
. The main page is inindex.html
. The Angular UI code consists of several components, which may be found insrc/app
.
The application also includes a domain layer, value objects, and a (simulated) persistence layer. Those layers are in subdirectories of src
. This architecture was an experiment to see how well Angular handled an approach outside of its comfort zone. It's not necessarily a pattern to follow in your own applications. (In particular, the way value objects are rendered was an experiment to see how well Angular could deal with an unusual architecture, not something to emulate.)
-
Unit Tests. All the code is unit tested. There are a few different styles used; my favorite is in
app/configuration_field/configuration-field.component.spec.ts
. That file also demonstrates how to test changes to a form field, something that wasn't well documented. -
Angular Services and Test Doubles. The
service_experiment
branch demonstrates using aConfigService
to get data from a (simulated) server. Look atsrc/app/app.component.ts
for the source code that uses the service andsrc/app/app.component.spec.ts
for its tests. -
Working Without Services. The
no_service_experiment
branch demonstrates the same ideas as theservice_experiment
branch, but does it completely without Angular's services infrastructure or dependency injection. It's actually simpler that way. Again, seesrc/app/app.component.ts
and its tests for the example.
See the screencasts for more information about the history of the sample app.
To try this code on your own computer:
- Install Node.js. This repo was built with Node v8.7.0.
- Download and unzip the source code into a convenient directory.
- Install angular-cli globally:
npm install -g angular-cli
- Rebuild modules:
npm rebuild
- Run
ng serve
- Open
http://localhost:4200
in a browser. - The page will automatically update when you make changes to the source code.
- Install Google Chrome if you haven't already.
- Run
ng test -sm=false
- The tests will automatically re-run when you make changes to the source code.
MIT License. See LICENSE.TXT
.