File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change 1
1
import { Injectable } from '@angular/core' ;
2
+ import { runInAction } from 'mobx' ;
2
3
import { action , observable } from 'mobx-angular' ;
3
4
5
+ import { NasaService } from '../shared/nasa.service' ;
6
+
4
7
@Injectable ( {
5
8
providedIn : 'root' ,
6
9
} )
7
10
export class AboutStoreService {
8
11
@observable title : string ;
9
12
10
- constructor ( ) {
13
+ constructor ( private nasaService : NasaService ) {
11
14
this . initialize ( ) ;
12
15
}
13
16
@@ -16,9 +19,11 @@ export class AboutStoreService {
16
19
this . title = 'about:hello world' ;
17
20
}
18
21
19
- @action
20
- randomTitle ( ) {
21
- // tslint:disable-next-line:no-magic-numbers
22
- this . title = Math . random ( ) . toString ( 32 ) ;
22
+ async randomTitle ( ) {
23
+ const response = await this . nasaService . getApod ( ) ;
24
+
25
+ runInAction ( ( ) => {
26
+ this . title = response . title ;
27
+ } ) ;
23
28
}
24
29
}
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ export class AboutComponent {
36
36
this . actions . getNasaApod ( ) ;
37
37
}
38
38
39
- updateTitle ( ) {
40
- this . store . about . randomTitle ( ) ;
39
+ async updateTitle ( ) {
40
+ await this . store . about . randomTitle ( ) ;
41
41
}
42
42
}
You can’t perform that action at this time.
0 commit comments