Skip to content

Commit ce5acd3

Browse files
add routing, unified cart service
1 parent ed1097d commit ce5acd3

25 files changed

+560
-76
lines changed

app/boot.js

Lines changed: 21 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/boot.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/boot.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import {bootstrap} from 'angular2/platform/browser'
22
import {AppComponent} from './components/app.component';
3+
import {ROUTER_PROVIDERS} from 'angular2/router';
34

4-
bootstrap(AppComponent);
5+
import {WarenkorbService} from './services/warenkorb.service';
6+
7+
bootstrap(AppComponent, [ROUTER_PROVIDERS, WarenkorbService]);

app/components/app.component.js

Lines changed: 57 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/components/app.component.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/components/app.component.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1-
import {Input, Component} from 'angular2/core';
2-
import {FORM_DIRECTIVES} from 'angular2/common';
1+
import {Component} from 'angular2/core';
2+
import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router';
3+
4+
import {BestellungComponent} from './bestellung/bestellung.component';
5+
import {UeberComponent} from './ueber/ueber.component';
6+
import {NavigationComponent} from './navigation/navigation.component';
7+
8+
@RouteConfig([{
9+
path: '/',
10+
component: BestellungComponent,
11+
name: 'Bestellung',
12+
useAsDefault: true
13+
}, {
14+
path: '/about',
15+
component: UeberComponent,
16+
name: 'Ueber'
17+
}])
318

419
@Component({
5-
selector: 'my-app',
20+
selector: 'app',
21+
directives: [ROUTER_DIRECTIVES, NavigationComponent],
622
template: `
7-
<h1>
8-
Heyho {{name}}
9-
</h1>
10-
<input [(ngModel)]="name">
23+
<navigation></navigation>
24+
<router-outlet></router-outlet>
1125
`
1226
})
13-
export class AppComponent {
14-
@Input() name : string;
15-
16-
constructor() {
17-
this.name = 'Alice';
18-
}
19-
}
27+
export class AppComponent {}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<form #suchFormular="ngForm">
2+
<label for="suche">Pizza-Suche</label>
3+
<br>
4+
<input type="text" name="suche" [(ngModel)]="suche" placeholder="Pizza-Name">
5+
</form>
6+
<table class="table">
7+
<tbody>
8+
<tr *ngFor="#pizza of pizzen">
9+
<td>{{index}}</td>
10+
<td>{{pizza.name}}</td>
11+
<td>{{pizza.preis | currency}}</td>
12+
<td>
13+
<a class="btn btn-default btn-sm" (click)="zumWarenkorb(pizza)">
14+
Hinzufügen
15+
</a>
16+
</tr>
17+
</tbody>
18+
</table>
19+
<warenkorb></warenkorb>

app/components/bestellung/bestellung.component.js

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/components/bestellung/bestellung.component.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import {Component, Input, OnInit} from 'angular2/core';
2+
import {NgForm} from 'angular2/common';
3+
4+
import {WarenkorbService} from '../../services/warenkorb.service';
5+
import {WarenkorbComponent} from '../warenkorb/warenkorb.component.ts';
6+
7+
interface Pizza {
8+
id: number,
9+
name: string,
10+
preis: number
11+
}
12+
13+
@Component({
14+
selector: 'bestellung',
15+
directives: [NgForm, WarenkorbComponent],
16+
templateUrl: './app/components/bestellung/bestellung.component.html'
17+
})
18+
export class BestellungComponent {
19+
@Input() suche: string;
20+
public pizzen = PIZZEN;
21+
public aktuellerWarenkorb;
22+
23+
constructor(private _warenkorbService: WarenkorbService) {
24+
}
25+
26+
zumWarenkorb(pizza: Pizza) {
27+
this._warenkorbService.addWarenkorb({
28+
name: pizza.name,
29+
preis: pizza.preis
30+
});
31+
}
32+
}
33+
34+
var PIZZEN: Pizza[] = [{
35+
id: 1,
36+
name: 'Pizza Vegetaria',
37+
preis: 10.99
38+
}, {
39+
id: 2,
40+
name: 'Pizza Salami',
41+
preis: 10.99
42+
}, {
43+
id: 3,
44+
name: 'Pizza Thunfisch',
45+
preis: 10.99
46+
}, {
47+
id: 4,
48+
name: 'Aktueller Flyer',
49+
preis: 0
50+
}];

0 commit comments

Comments
 (0)