Skip to content

Commit d8d7b40

Browse files
committed
C14T1-Start
1 parent 1878394 commit d8d7b40

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

app/app.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component } from '@angular/core';
22
import { RacesComponent } from './races.component';
33
import { RaceService } from './race.service';
44

5+
56
@Component({
67
selector: 'racing-app',
78
template: `

app/race.service.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import { RACES } from './mocks';
22
import { Injectable } from '@angular/core';
3+
import { Http } from '@angular/http';
4+
import { Race } from './race';
5+
import 'rxjs/add/operator/map';
36

47
@Injectable()
58
export class RaceService {
9+
10+
11+
612
getRaces() {
7-
return RACES;
13+
return
814
}
915
}

app/races.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h2>Cash left to enter races: <span>{{cashLeft() | currency:'USD':true}}</span>
1111
<tr>
1212
<td>
1313
<h3>{{race.name}}</h3>
14-
<p class="date">{{race.date | date:'yMMMdhm'}}</p>
14+
<p class="date">{{castDate(race.date) | date:'yMMMdhm'}}</p>
1515
<p class="description">{{race.about}}</p>
1616
</td>
1717
<td>

app/races.component.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,23 @@ export class RacesComponent {
1515
constructor(private raceService: RaceService) { }
1616

1717
ngOnInit() {
18-
this.races = this.raceService.getRaces();
18+
this.raceService.getRaces() ;
1919
}
2020

2121
totalCost() {
2222
let sum = 0;
23-
for (let race of this.races) {
24-
if (race.isRacing) sum += race.entryFee;
23+
if (this.races) {
24+
for (let race of this.races) {
25+
if (race.isRacing) sum += race.entryFee;
26+
}
2527
}
2628
return sum;
2729
}
2830

31+
castDate(date) {
32+
return new Date(date);
33+
}
34+
2935
cashLeft() {
3036
return this.cash - this.totalCost();
3137
}

app/races.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"racesData":[
3+
{
4+
"id": 1,
5+
"name": "Daytona Thunderdome",
6+
"date": "2512-01-04T14:00:00",
7+
"about": "Race through the ruins of an ancient Florida battle arena.",
8+
"entryFee": 3200,
9+
"isRacing": false,
10+
"image": "/images/daytona_thunderdome.jpg",
11+
"imageDescription": "Race track with laser lanes"
12+
}, {
13+
"id": 2,
14+
"name": "San Francisco Ruins",
15+
"date": "2512-07-03T20:00:00",
16+
"about": "Drift down the streets of a city almost sunk under the ocean.",
17+
"entryFee": 4700,
18+
"isRacing": false,
19+
"image": "/images/san_francisco_ruins.jpg",
20+
"imageDescription": "Golden Gate Bridge with lasers"
21+
}, {
22+
"id": 3,
23+
"name": "New York City Skyline",
24+
"date": "2512-07-12T21:00:00",
25+
"about": "Fly between buildings in the electronic sky.",
26+
"entryFee": 4300,
27+
"isRacing": true,
28+
"image": "/images/new_york_city_skyline.jpg",
29+
"imageDescription": "Bridge overlooking New York City"
30+
}
31+
]
32+
}

0 commit comments

Comments
 (0)