File tree Expand file tree Collapse file tree 5 files changed +50
-5
lines changed Expand file tree Collapse file tree 5 files changed +50
-5
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { Component } from '@angular/core';
2
2
import { RacesComponent } from './races.component' ;
3
3
import { RaceService } from './race.service' ;
4
4
5
+
5
6
@Component ( {
6
7
selector : 'racing-app' ,
7
8
template : `
Original file line number Diff line number Diff line change 1
1
import { RACES } from './mocks' ;
2
2
import { Injectable } from '@angular/core' ;
3
+ import { Http } from '@angular/http' ;
4
+ import { Race } from './race' ;
5
+ import 'rxjs/add/operator/map' ;
3
6
4
7
@Injectable ( )
5
8
export class RaceService {
9
+
10
+
11
+
6
12
getRaces ( ) {
7
- return RACES ;
13
+ return
8
14
}
9
15
}
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ <h2>Cash left to enter races: <span>{{cashLeft() | currency:'USD':true}}</span>
11
11
< tr >
12
12
< td >
13
13
< h3 > {{race.name}}</ h3 >
14
- < p class ="date "> {{race.date | date:'yMMMdhm'}}</ p >
14
+ < p class ="date "> {{castDate( race.date) | date:'yMMMdhm'}}</ p >
15
15
< p class ="description "> {{race.about}}</ p >
16
16
</ td >
17
17
< td >
Original file line number Diff line number Diff line change @@ -15,17 +15,23 @@ export class RacesComponent {
15
15
constructor ( private raceService : RaceService ) { }
16
16
17
17
ngOnInit ( ) {
18
- this . races = this . raceService . getRaces ( ) ;
18
+ this . raceService . getRaces ( ) ;
19
19
}
20
20
21
21
totalCost ( ) {
22
22
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
+ }
25
27
}
26
28
return sum ;
27
29
}
28
30
31
+ castDate ( date ) {
32
+ return new Date ( date ) ;
33
+ }
34
+
29
35
cashLeft ( ) {
30
36
return this . cash - this . totalCost ( ) ;
31
37
}
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments