1
+ import { Component , OnInit , OnDestroy } from '@angular/core' ;
2
+ import { ActivatedRoute } from "@angular/router" ;
3
+ import { Http } from '@angular/http' ;
4
+ import { ResultJson } from "../../models/ResultJson" ;
5
+ import { BookBaseViewModel } from "../../models/Book" ;
6
+
7
+ @Component ( {
8
+ selector : 'seriesProfile' ,
9
+ templateUrl : './seriesProfile.component.html'
10
+ } )
11
+
12
+ export class SeriesProfileComponent implements OnInit , OnDestroy {
13
+ constructor ( private route : ActivatedRoute , public http : Http ) {
14
+ }
15
+
16
+ loading = false ;
17
+ success = true ;
18
+ baseApiUrl = 'http://dwcheckapi.azurewebsites.net/Books/Series' ;
19
+ seriesId : number ;
20
+ books : BookBaseViewModel [ ] ;
21
+
22
+
23
+ private subscription : any ;
24
+
25
+ ngOnInit ( ) {
26
+ this . subscription = this . route . params . subscribe ( params => {
27
+ this . seriesId = + params [ 'id' ] ; // the + here converts a string to a number
28
+
29
+ var route = `${ this . baseApiUrl } /${ this . seriesId } ` ;
30
+
31
+ this . http . get ( route ) . subscribe ( ( result ) => {
32
+ var resultJson = result . json ( ) as ResultJson ;
33
+ debugger ;
34
+ if ( resultJson . success ) {
35
+ this . books = [ ] ;
36
+ result . json ( ) . result . forEach ( ( serverBook : ApiBookBaseViewModel ) => {
37
+ this . books . push ( new BookBaseViewModel ( serverBook . bookDescription , serverBook . bookCoverImageUrl ) ) ;
38
+ } ) ;
39
+ }
40
+ this . success = resultJson . success ;
41
+ this . loading = false ;
42
+ } ) ;
43
+ } ) ;
44
+ }
45
+
46
+
47
+ ngOnDestroy ( ) {
48
+ this . subscription . unsubscribe ( ) ;
49
+ }
50
+ }
51
+
52
+ interface ApiBookBaseViewModel {
53
+ bookCoverImageUrl : string ;
54
+ bookDescription : string ;
55
+ }
0 commit comments