-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.component.ts
More file actions
40 lines (37 loc) · 1.18 KB
/
Copy pathapp.component.ts
File metadata and controls
40 lines (37 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Component, OnChanges, ViewChild, OnInit } from '@angular/core';
import { TrainersService } from './trainers.service';
import { TrainersComponent } from './trainers.component';
import { TrainerShowComponent } from './trainer_show.component'
// import {Observable} from 'rxjs/Observable';
// import { Http, Response } from '@angular/http';
// import 'rxjs/add/operator/map';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['./app.component.css'],
providers: [TrainersService]
})
export class AppComponent implements OnChanges{
trainers: any;
trainer: any;
@ViewChild(TrainerShowComponent) info: TrainerShowComponent;
constructor(private trainersService: TrainersService) {
this.trainersService.getData().subscribe( (data: any) =>{
this.trainers = data.trainers;
});
}
ngOnInit() {}
ngOnChanges() {
this.trainers = null;
setTimeout( () => {
this.trainersService.getData().subscribe((data: any) => {
this.trainers = data.trainers;
});
});
}
getDetail(id: number) {
this.trainersService.getDetail().subscribe((data: any) => {
this.trainer = data.trainers[id];
});
}
}