1
1
import { Component , OnInit } from '@angular/core' ;
2
- import { NasaResponse } from "../../../models/NasaResponse" ;
3
- import { NasaService } from "../../../services/nasa.service" ;
4
2
import { MessageService } from "primeng/api" ;
3
+ import { NasaService } from "../../../services/nasa.service" ;
4
+ import { ApodResponse } from "../../../models/ApodResponse" ;
5
5
import { EnumsNasa } from "../../../shared/enums" ;
6
6
7
7
@Component ( {
@@ -10,9 +10,9 @@ import {EnumsNasa} from "../../../shared/enums";
10
10
styleUrls : [ './apod.component.scss' ]
11
11
} )
12
12
export class ApodComponent implements OnInit {
13
- nasaResponse : NasaResponse ;
13
+ nasaResponse : ApodResponse ;
14
14
title : string ;
15
- display = false ;
15
+ loading = false ;
16
16
17
17
constructor ( private _nasaService : NasaService ,
18
18
private _messageService : MessageService ) {
@@ -23,14 +23,26 @@ export class ApodComponent implements OnInit {
23
23
this . getNasaData ( ) ;
24
24
}
25
25
26
- getNasaData ( ) : void {
27
- this . _nasaService . getNasaApod ( )
28
- . then ( data => {
26
+ getNasaData ( params ?: string ) : void {
27
+ this . nasaResponse = new ApodResponse ( ) ;
28
+ this . loading = true ;
29
+ this . _nasaService . getNasaApod ( params ? params : '' ) . subscribe ( {
30
+ next : ( data ) => {
29
31
this . nasaResponse = data ;
30
- this . display = true ;
31
- } )
32
- . catch ( err => {
33
- this . _messageService . add ( { severity : 'error' , summary : 'Error' , detail : 'Error retrieving data from NASA' } ) ;
34
- } ) ;
32
+ this . loading = false ;
33
+ } ,
34
+ error : ( err ) => {
35
+ // console.log(err)
36
+ this . nasaResponse = new ApodResponse ( ) ;
37
+ this . loading = false ;
38
+ this . _messageService . add ( { severity : 'error' , summary : 'Error' , detail : err . error . msg || 'Error retrieving data from NASA' } ) ;
39
+ }
40
+ } ) ;
35
41
}
42
+
43
+ searchNasaData ( event : string ) {
44
+ // console.log(event);
45
+ this . getNasaData ( event ) ;
46
+ }
47
+
36
48
}
0 commit comments