<!DOCTYPE html>
<html>
<head>
<title>angular2 playground</title>
<link rel="stylesheet" href="style.css" />
<script src="https://npmcdn.com/zone.js@0.6.12/dist/zone.js"></script>
<script src="https://npmcdn.com/reflect-metadata@0.1.3/Reflect.js"></script>
<script src="https://npmcdn.com/systemjs@0.19.31/dist/system.js"></script>
<script src="https://npmcdn.com/typescript@1.8.10/lib/typescript.js"></script>
<script src="config.js"></script>
<script>
System.import('app')
.catch(console.error.bind(console));
</script>
</head>
<body>
<my-app>
loading...
</my-app>
</body>
</html>
/* Styles go here */
### Angular2 Starter Plunker - Typescript - RC.0
A simple plunker demonstrating Angular2 usage:
- Uses SystemJS + TypeScript to compile on the fly
- Includes binding, directives, http, pipes, and DI usage.
System.config({
//use typescript for compilation
transpiler: 'typescript',
//typescript compiler options
typescriptOptions: {
emitDecoratorMetadata: true
},
//map tells the System loader where to look for things
map: {
app: "./src",
'@angular': 'https://npmcdn.com/@angular',
'rxjs': 'https://npmcdn.com/rxjs@5.0.0-beta.6'
},
//packages defines our app package
packages: {
app: {
main: './main.ts',
defaultExtension: 'ts'
},
'@angular/core': {
main: 'bundles/core.umd.js',
defaultExtension: 'js'
},
'@angular/http': {
main: 'bundles/http.umd.js',
defaultExtension: 'js'
},
'@angular/compiler': {
main: 'bundles/compiler.umd.js',
defaultExtension: 'js'
},
'@angular/common': {
main: 'bundles/common.umd.js',
defaultExtension: 'js'
},
'@angular/platform-browser-dynamic': {
main: 'bundles/platform-browser-dynamic.umd.js',
defaultExtension: 'js'
},
'@angular/platform-browser': {
main: 'bundles/platform-browser.umd.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
});
//main entry point
import {bootstrap} from '@angular/platform-browser-dynamic';
import {App} from './app';
bootstrap(App, [])
.catch(err => console.error(err));
//our root app component
import {Component} from '@angular/core'
import {ItemsService} from './items.service';
import 'rxjs/add/operator/toPromise';
import {Http, HTTP_PROVIDERS} from '@angular/http';
@Component({
selector: 'my-app',
providers: [ItemsService,HTTP_PROVIDERS],
templateUrl: 'src/app.html' ,
directives: []
})
export class App {
constructor(private _itemsService:ItemsService) {}
items
loadItems(){
this._itemsService.getItems()
.subscribe(res=>this.items= res);
}
reloadItems(){
this._itemsService.getItems()
.toPromise()
.then(res=>{
let newData = res;
for (let itemParent of this.items){
for(let newDataParent of newData){
for(let newDataChild of newDataParent.children) {
let xx = itemParent.children.find(yy => yy.id == newDataChild.id);
if(xx !== undefined){
console.log(xx);
if(xx.text != newDataChild.text){
xx.text = newDataChild.text;
}
else{
xx.text = "same same";
}
}
}
}
}
});
}
{
"items":[
{
"id":1,
"text":"XX item",
"children":[
{
"id":100010,
"text": "XX item 9:00am 10 Pax"
},
{
"id":100011,
"text": "XX item 10:00am 10 Pax"
},
{
"id":100012,
"text": "XX item 11:00am 10 Pax"
}
]
},
{
"id":5,
"text":"YY item",
"children":[
{
"id":100013,
"text": "YY item 9:00am 1 Pax"
},
{
"id":100014,
"text": "YY item 10:00am 1Pax"
},
{
"id":100015,
"text": "YY item 11:00am 1 Pax"
}
]
},
{
"id":3,
"text":"ZZ item",
"children":[
{
"id":100016,
"text": "ZZ item 9:00am 3 Pax"
},
{
"id":100017,
"text": "ZZ item 10:00am 10 Pax"
},
{
"id":100018,
"text": "ZZ item 11:00am 10 Pax"
}
]
},
{
"id":4,
"text":"AA item",
"children":[
{
"id":100019,
"text": "AA item 9:00am 10 Pax"
},
{
"id":100020,
"text": "AA item 10:00am 10 Pax"
},
{
"id":100021,
"text": "AA item 11:00am 3 Pax"
},
{
"id":100022,
"text": "AA item 12:00am 10 Pax"
}
]
}
]
}
import {Injectable} from '@angular/core';
import {Http} from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class ItemsService{
constructor(private _http: Http){}
getItems(){ //Todo add date,businessunit params here
return this._http.get('src/items.json')
.map(this.extractData);
}
private extractData(res){
let body = res.json().items;
console.log(body);
return body;
}
}
<button class="btn btn-default" id='loadTours' (click)="loadItems()" >Load Items</button>
<button class="btn btn-default" id='reloadTours' (click)="reloadItems()" >Reload Items</button>
<div *ngIf="items">
<div class="holder">
<div *ngFor="let item of items">
<div ><b>{{item.text}}</b>
<div *ngIf='item.children'>
<div *ngFor='let child of item.children' class="tour">
<span class="handle">+</span><span id='{{child.id}}'>{{child.text}} </span>
</div>
</div>
</div>
</div>
</div>
</div>