This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderComponent { | |
@Input() stockSymbol: string; | |
@Input() quantity: number; | |
} | |
class PriceQuoterComponent { | |
@Output() lastPrice: EventEmitter<IPriceQuote> = new EventEmitter(); | |
... | |
this.lastPrice.emit(priceQuote) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppComponent { | |
products: Array = []; | |
constructor(private http: Http) { | |
this.http.get('/products') | |
.map(res => res.json()) | |
.subscribe( | |
data => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<app>Loading...</app> | |
<script> | |
System.config({ | |
transpiler: 'typescript', | |
typescriptOptions: {emitDecoratorMetadata: true}, | |
packages: {app: {defaultExtension: 'ts'}} | |
}); | |
System.import('app'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Angular2 Http Demo</title> | |
<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> | |
<script src="systemjs.config.js"></script> | |
<script> | |
System.import('app').catch(function(err){ console.error(err); }); | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(global) { | |
// map tells the System loader where to look for things | |
var map = { | |
'app': 'app', // 'dist', | |
'@angular': 'node_modules/@angular', | |
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api', | |
'rxjs': 'node_modules/rxjs' | |
}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {bootstrap} from '@angular/platform-browser-dynamic'; | |
import {HTTP_PROVIDERS} from '@angular/http'; | |
import {AppComponent} from './app.component' | |
bootstrap(AppComponent, [ | |
HTTP_PROVIDERS | |
]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Component} from '@angular/core'; | |
import {Http, Response} from '@angular/http'; | |
import {Observable} from 'rxjs/Rx'; | |
@Component({ | |
selector: 'demo-app', | |
template:` | |
<h1>Angular2 HTTP Demo App</h1> | |
<h2>Foods</h2> | |
<ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ngOnInit() { | |
this.getFoods(); | |
} | |
getFoods() { | |
this.http.get('/app/food.json') | |
.map((res:Response) => res.json()) | |
.subscribe( | |
data => { this.foods = data}, | |
err => console.error(err), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ngOnInit() { | |
... | |
this.getBooksAndMovies(); // <-- add this line | |
} | |
getBooksAndMovies() { | |
Observable.forkJoin( | |
this.http.get('/app/books.json').map((res:Response) => res.json()), | |
this.http.get('/app/movies.json').map((res:Response) => res.json()) | |
).subscribe( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Observable} from 'rxjs/Rx'; | |
@Injectable() | |
export class DemoService { | |
constructor(private http:Http) { } | |
// Uses http.get() to load a single JSON file | |
getFoods() { | |
return this.http.get('/app/food.json').map((res:Response) => res.json()); |