diff --git a/README.md b/README.md
index 8fc6118..b58c3e5 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,19 @@
-# angular2byexample
-Source code repository for the book "Angular2 by Example"
+# Angular2 By Example
+
+[](https://www.packtpub.com/web-development/angular-2-example)
+
+Source code repository for the book [Angular2 by Example](https://www.packtpub.com/web-development/angular-2-example)
+
+**Releasing soon!!**
+
+To setup code for Guess The Number see the README.md in **guessthenumber** folder.
+
+To setup code for Personal Trainer see the README.md in **trainer** folder.
+
+## Note
+
+The **master** branch contains the final outcome for both the samples we build throughout the book.
+
+Chapter progress is tracked using individual branches. Each **chapter has checkpoints** and each checkpoint code is **available on a seperate branch**.
+
+For example, branches *base*, *checkpoint2.1*, *checkpoint2.2*, *checkpoint2.3* and *checkpoint2.4* contain code checkpoints for **Chapter 2**.
diff --git a/guessthenumber/app.ts b/guessthenumber/app.ts
deleted file mode 100644
index 4e02bbe..0000000
--- a/guessthenumber/app.ts
+++ /dev/null
@@ -1,51 +0,0 @@
-//import 'zone.js';
-//import 'reflect-metadata';
-import {
-Component, View, bootstrap
-}from 'angular2/angular2';
-
-@Component({
- selector: 'my-app'
-})
-@View({
- template: `
-
-
Guess the Number !
-
Guess the computer generated random number between 1 and 1000.
-
Your Guess:
-
-
Verify
-
Restart
-
-
=0" class="alert alert-warning">Your guess is higher.
-
Your guess is lower.
-
Yes! That"s it.
-
-
No of guesses :
- {{noOfTries}}
-
-
-`
-})
-class GuessTheNumberComponent {
- deviation: number;
- noOfTries: number;
- original: number;
- guess: number;
-
- constructor() {
- this.initializeGame();
- }
- verifyGuess() {
- this.deviation = this.original - this.guess;
- this.noOfTries = this.noOfTries + 1;
- }
- initializeGame() {
- this.noOfTries = 0;
- this.original = Math.floor((Math.random() * 1000) + 1);
- this.guess = null;
- this.deviation = null;
- }
-}
-
-bootstrap(GuessTheNumberComponent);
diff --git a/guessthenumber/app/app.module.ts b/guessthenumber/app/app.module.ts
new file mode 100644
index 0000000..710d89b
--- /dev/null
+++ b/guessthenumber/app/app.module.ts
@@ -0,0 +1,12 @@
+import { NgModule } from '@angular/core';
+import { BrowserModule } from '@angular/platform-browser';
+
+import { GuessTheNumberComponent } from './guess-the-number.component';
+
+@NgModule({
+ imports: [ BrowserModule ],
+ declarations: [ GuessTheNumberComponent ],
+ bootstrap: [ GuessTheNumberComponent ]
+})
+
+export class AppModule { }
diff --git a/guessthenumber/app/guess-the-number.component.ts b/guessthenumber/app/guess-the-number.component.ts
new file mode 100644
index 0000000..0992fb2
--- /dev/null
+++ b/guessthenumber/app/guess-the-number.component.ts
@@ -0,0 +1,43 @@
+import { Component }from '@angular/core';
+
+@Component({
+ selector: 'my-app',
+ template: `
+
+
Guess the Number !
+
Guess the computer generated random number between 1 and 1000.
+
Your Guess:
+
+
Verify
+
Restart
+
+
Your guess is higher.
+
0" class="alert alert-warning">Your guess is lower.
+
Yes! That's it.
+
+
No of guesses :
+ {{noOfTries}}
+
+
+ `
+})
+export class GuessTheNumberComponent {
+ deviation: number;
+ noOfTries: number;
+ original: number;
+ guess: number;
+
+ constructor() {
+ this.initializeGame();
+ }
+ initializeGame() {
+ this.noOfTries = 0;
+ this.original = Math.floor((Math.random() * 1000) + 1);
+ this.guess = null;
+ this.deviation = null;
+ }
+ verifyGuess() {
+ this.deviation = this.original - this.guess;
+ this.noOfTries = this.noOfTries + 1;
+ }
+}
\ No newline at end of file
diff --git a/guessthenumber/app/main.ts b/guessthenumber/app/main.ts
new file mode 100644
index 0000000..44f34b2
--- /dev/null
+++ b/guessthenumber/app/main.ts
@@ -0,0 +1,6 @@
+import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
+
+import { AppModule } from './app.module';
+
+const platform = platformBrowserDynamic();
+platform.bootstrapModule(AppModule);
diff --git a/guessthenumber/index.html b/guessthenumber/index.html
index 8f843f8..c351c05 100644
--- a/guessthenumber/index.html
+++ b/guessthenumber/index.html
@@ -1,25 +1,19 @@
-
-
- Guess the Number!
-
-
-
-
-
-
-
-
- Loading...
-
-
+
+ Guess the Number!
+
+
+
+
+
+
+
+
+
+
+ Loading...
+
diff --git a/guessthenumber/systemjs.config.js b/guessthenumber/systemjs.config.js
new file mode 100644
index 0000000..c7fa815
--- /dev/null
+++ b/guessthenumber/systemjs.config.js
@@ -0,0 +1,24 @@
+System.config({
+ map : {
+ 'app': 'app',
+ 'rxjs': 'https://unpkg.com/rxjs@5.0.0-beta.12',
+ '@angular/common': 'https://unpkg.com/@angular/common@2.0.0',
+ '@angular/compiler': 'https://unpkg.com/@angular/compiler@2.0.0',
+ '@angular/core': 'https://unpkg.com/@angular/core@2.0.0',
+ '@angular/platform-browser': 'https://unpkg.com/@angular/platform-browser@2.0.0',
+ '@angular/platform-browser-dynamic': 'https://unpkg.com/@angular/platform-browser-dynamic@2.0.0'
+ },
+ packages:{
+ 'app': { main: 'main.ts', defaultExtension: 'ts' },
+ '@angular/common': { main: 'bundles/common.umd.js', defaultExtension: 'js' },
+ '@angular/compiler': { main: 'bundles/compiler.umd.js', defaultExtension: 'js' },
+ '@angular/core': { main: 'bundles/core.umd.js', defaultExtension: 'js' },
+ '@angular/platform-browser': { main: 'bundles/platform-browser.umd.js', defaultExtension: 'js' },
+ '@angular/platform-browser-dynamic': { main: 'bundles/platform-browser-dynamic.umd.js', defaultExtension: 'js' },
+ },
+ // DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
+ transpiler: 'typescript',
+ typescriptOptions: {
+ emitDecoratorMetadata: true
+ }
+});
\ No newline at end of file
diff --git a/trainer/.gitignore b/trainer/.gitignore
index f06235c..c5ac28a 100644
--- a/trainer/.gitignore
+++ b/trainer/.gitignore
@@ -1,2 +1,3 @@
node_modules
dist
+typings/**
\ No newline at end of file
diff --git a/trainer/README.md b/trainer/README.md
index eb6a127..8a4b300 100644
--- a/trainer/README.md
+++ b/trainer/README.md
@@ -1,3 +1,24 @@
# Personal Trainer
Personal Trainer built using Angular2 and TypeScript
+
+## Install
+
+Clone this repo and execute in your favourite shell:
+
+* `npm i -g gulp` to install gulp globally (if you don't have it installed already)
+* `npm install` to install local npm dependencies
+
+## Play
+
+After completing installation type in your favourite shell:
+
+* `gulp play` to start the app in a new browser window. App files are observed and will be re-transpiled on each change.
+
+> ~~If you see a bunch of **TypeScript** compilation errors while running `gulp play`, the required **typings** did not get installed. While `npm install` should also install the typings, at times this does not happen.
+> To fix this, try to install typings again with command `npm run typings install`.
+> If the typing installation throws error try to upgrade the typing global installation with command `npm install typings -g` and then run the command `npm run typings install` again.~~
+
+> The old approach of using the `typings` tool to install typings has been abandoned in favour of **npm** based typing supported by new versions of **TypeScript** compiler. Take latest of the code and upgrade to latest version of TypeScript compiler. `npm install` should now install all typings.
+
+> **Note**: The book content still show use of `typings`, you can disregard it.
diff --git a/trainer/gulpfile.js b/trainer/gulpfile.js
index c5de7e8..d0e205d 100644
--- a/trainer/gulpfile.js
+++ b/trainer/gulpfile.js
@@ -1,45 +1,56 @@
var gulp = require('gulp');
+var connect = require('gulp-connect');
var PATHS = {
- src: 'src/**/*.ts'
+ src: 'src/**/*.ts',
+ html: 'src/**/*.html',
+ css: 'src/**/*.css'
};
-gulp.task('clean', function (done) {
- var del = require('del');
- del(['dist'], done);
+gulp.task('clean', function(done) {
+ var del = require('del');
+ del(['dist'], done);
});
-gulp.task('ts2js', function () {
- var typescript = require('gulp-typescript');
- var sourcemaps = require('gulp-sourcemaps');
-
- var tsResult = gulp.src(PATHS.src)
- .pipe(sourcemaps.init())
- .pipe(typescript({
- noImplicitAny: true,
- module: 'system',
- target: 'ES5',
- moduleResolution: 'node',
- emitDecoratorMetadata: true,
- experimentalDecorators: true
- }));
-
- return tsResult.js
- .pipe(sourcemaps.write())
- .pipe(gulp.dest('dist'));
+gulp.task('ts2js', function() {
+ var typescript = require('gulp-typescript');
+ var sourcemaps = require('gulp-sourcemaps');
+
+ var tsResult = gulp.src(PATHS.src)
+ .pipe(sourcemaps.init())
+ .pipe(typescript({
+ noImplicitAny: true,
+ module: 'system',
+ target: 'ES5',
+ moduleResolution: 'node',
+ emitDecoratorMetadata: true,
+ experimentalDecorators: true
+ }));
+
+ return tsResult.js
+ .pipe(sourcemaps.write())
+ .pipe(gulp.dest('dist'))
+ .pipe(connect.reload());
});
-gulp.task('play', ['ts2js'], function () {
- var http = require('http');
- var connect = require('connect');
- var serveStatic = require('serve-static');
- var open = require('open');
+gulp.task('play', ['ts2js'], function() {
+ var http = require('http');
+ var open = require('open');
+ var watch = require('gulp-watch');
- var port = 9000, app;
- gulp.watch(PATHS.src, ['ts2js']);
- app = connect().use(serveStatic(__dirname));
- http.createServer(app).listen(port, function () {
- open('http://localhost:' + port);
- });
+ var port = 9000,
+ app;
+
+ connect.server({
+ root: __dirname,
+ port: port,
+ livereload: true,
+ fallback: 'index.html'
+ });
+ open('http://localhost:' + port + '/index.html');
+
+ gulp.watch(PATHS.src, ['ts2js']);
+ watch(PATHS.html).pipe(connect.reload());
+ watch(PATHS.css).pipe(connect.reload());
});
diff --git a/trainer/index.html b/trainer/index.html
index 174563f..862f163 100644
--- a/trainer/index.html
+++ b/trainer/index.html
@@ -8,24 +8,26 @@
-
+
+
- Loading...
+ Loading...
-
-
+
+
+
+
+
+
+
+
-
-
-
+