Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0301d71
Removed audio workout functionality. Moving it to chapter 3.
chandermani Dec 7, 2015
665ecea
Added nav bar and fixed container style
chandermani Dec 8, 2015
0411dba
Remove redundant imports.
chandermani Dec 14, 2015
af9539f
Package version fixed for angular.
chandermani Dec 14, 2015
f027763
Fixed readme and package urls
chandermani Dec 14, 2015
96bc29e
Upgraded to angular beta.
chandermani Dec 17, 2015
954c6fb
Enable routing.
chandermani Dec 19, 2015
e6e8676
Moved the html template to app.ts
chandermani Dec 23, 2015
ffe4233
Upgraded to Angular 2.0.0 beta 15
chandermani Apr 17, 2016
dc09f21
Fixed SPA HTML5 mode. C'hanged gulp to use gulp-connect.
chandermani Apr 17, 2016
d3b1155
Upgraded to Angular 2 rc1, and upgraded router
chandermani May 15, 2016
e3225ae
Refactoring according to style guide.
chandermani May 10, 2016
c8729b0
Removed reference for deprecated router
chandermani May 17, 2016
d199350
Removed _ from variable name
chandermani May 18, 2016
7b3e294
Remove _ for private variable.
chandermani May 19, 2016
deeed0d
Upgraded to angular rc2
chandermani Jun 18, 2016
7ba708c
Upgraded router to 3.0.0 beta7
chandermani Jun 22, 2016
1c7b49d
Fixed checkpoint2.3 video-player, to sanitize video content using Dom…
chandermani Jun 21, 2016
f304d1b
Upgraded to angular rc4
chandermani Jul 1, 2016
547acce
Fixed minor code issue in checkpoint2.3. Merged with 2.4
chandermani Jul 8, 2016
6c6c79d
Updated systemjs to support bundled umd files
chandermani Jul 9, 2016
c99dfb3
Updated ES6 typing definition to use core-js
chandermani Jul 30, 2016
0cf0394
Update GuessTheNumber to RC4
kevinhennessy Aug 24, 2016
09154b9
Fixed router with 3.0.0 beta.2
chandermani Aug 15, 2016
cdb542a
Update README.md
chandermani Aug 28, 2016
017ead6
Update README.md
chandermani Aug 28, 2016
e9c5700
Upgrade GTN to final release
kevinhennessy Sep 16, 2016
3cac30c
Replace npmcdn.com with unpkg.com
kevinhennessy Sep 19, 2016
cca23a0
Update rxjs version in GTN
kevinhennessy Sep 19, 2016
7046774
Upgraded to Angular 2.0.0. Added module for workout-runner
chandermani Aug 15, 2016
2c981a6
Changed the empty path to wild card path.
chandermani Sep 29, 2016
1035303
Removed typings tool. Typings will come as npm package. Upgraded gulp…
chandermani Mar 9, 2017
d3ac171
Updated readme describing the new way to instal typings
chandermani Mar 15, 2017
d72d62d
Removed extra typing install instructions.
chandermani Mar 15, 2017
9a1d113
lock dependency on types core js to 0 9 36
kevinhennessy Mar 27, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# angular2byexample
Source code repository for the book "Angular2 by Example"
# Angular2 By Example

[![Angular2 By Example Front Cover](https://d1ldz4te4covpm.cloudfront.net/sites/default/files/imagecache/ppv4_main_book_cover/B05079_MockupCover_Normal.jpg)](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**.
51 changes: 0 additions & 51 deletions guessthenumber/app.ts

This file was deleted.

12 changes: 12 additions & 0 deletions guessthenumber/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -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 { }
43 changes: 43 additions & 0 deletions guessthenumber/app/guess-the-number.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Component }from '@angular/core';

@Component({
selector: 'my-app',
template: `
<div class="container">
<h2>Guess the Number !</h2>
<p class="well lead">Guess the computer generated random number between 1 and 1000.</p>
<label>Your Guess: </label>
<input type="number" [value]="guess" (input)="guess = $event.target.value" />
<button (click)="verifyGuess()" class="btn btn-primary btn-sm">Verify</button>
<button (click)="initializeGame()" class="btn btn-warning btn-sm">Restart</button>
<div>
<p *ngIf="deviation<0" class="alert alert-warning">Your guess is higher.</p>
<p *ngIf="deviation>0" class="alert alert-warning">Your guess is lower.</p>
<p *ngIf="deviation===0" class="alert alert-success">Yes! That's it.</p>
</div>
<p class="text-info">No of guesses :
<span class="badge">{{noOfTries}}</span>
</p>
</div>
`
})
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;
}
}
6 changes: 6 additions & 0 deletions guessthenumber/app/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app.module';

const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);
38 changes: 16 additions & 22 deletions guessthenumber/index.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
<!DOCTYPE html>
<html>

<head>
<title>Guess the Number!</title>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.angularjs.org/tools/system.js"></script>
<script src="https://code.angularjs.org/tools/typescript.js"></script>
<script src="https://code.angularjs.org/2.0.0-alpha.44/angular2.dev.js"></script>
<script>
System.config({
transpiler: 'typescript',
typescriptOptions: {
emitDecoratorMetadata: true
}
});
System.import('./app.ts');
</script>
</head>

<body>
<my-app>Loading...</my-app>
</body>

<head>
<title>Guess the Number!</title>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<script src="https://unpkg.com/core-js/client/shim.min.js"></script>
<script src="https://unpkg.com/[email protected]"></script>
<script src="https://unpkg.com/[email protected]?main=browser"></script>
<script src="https://unpkg.com/[email protected]/lib/typescript.js"></script>
<script src="https://unpkg.com/[email protected]/dist/system.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
</head>
<body>
<my-app>Loading...</my-app>
</body>
</html>
24 changes: 24 additions & 0 deletions guessthenumber/systemjs.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
System.config({
map : {
'app': 'app',
'rxjs': 'https://unpkg.com/[email protected]',
'@angular/common': 'https://unpkg.com/@angular/[email protected]',
'@angular/compiler': 'https://unpkg.com/@angular/[email protected]',
'@angular/core': 'https://unpkg.com/@angular/[email protected]',
'@angular/platform-browser': 'https://unpkg.com/@angular/[email protected]',
'@angular/platform-browser-dynamic': 'https://unpkg.com/@angular/[email protected]'
},
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
}
});
1 change: 1 addition & 0 deletions trainer/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
typings/**
20 changes: 20 additions & 0 deletions trainer/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# 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.
> 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.
77 changes: 44 additions & 33 deletions trainer/gulpfile.js
Original file line number Diff line number Diff line change
@@ -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());
});
25 changes: 14 additions & 11 deletions trainer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,27 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
<link href="//fonts.googleapis.com/css?family=Roboto+Slab:100,300,400,700" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="static/css/app.css" />
<link rel="stylesheet" href="/static/css/app.css" />
<base href="/">
</head>

<body>
<trainer-app>Loading...</trainer-app>
<trainer-app>Loading...</trainer-app>
</body>

<!-- ES6-related imports -->
<script src="/node_modules/systemjs/dist/system.js"></script>
<!-- Libraries imports -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>

<!-- Configure SystemJS -->
<script src="systemjs.config.js"></script>

<script>
//configure system loader
System.config({defaultJSExtensions: true});
</script>
<script src="/node_modules/angular2/bundles/angular2.dev.js"></script>
<script>

//bootstrap the Angular2 application
System.import('dist/bootstrap').catch(console.log.bind(console));
System.import('app').catch(console.log.bind(console));
</script>

<script src="http://localhost:35729/livereload.js"></script>
</html>
Loading