-
Notifications
You must be signed in to change notification settings - Fork 0
/
reporters.component.ts
61 lines (52 loc) · 1.62 KB
/
reporters.component.ts
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Component, OnInit } from '@angular/core'
import { ReportersService } from './../services/reporters.service'
import { Reporter } from './../interfaces/reporter'
import { MatDialog } from '@angular/material/dialog'
import { ReportersDialogComponent } from './reporters-dialog/reporters-dialog.component'
@Component({
selector: 'app-reporters',
templateUrl: './reporters.component.html',
styleUrls: ['./reporters.component.scss']
})
export class ReportersComponent implements OnInit {
reporters: Reporter[] = []
loading = false
displayedColumns = ['id', 'name', 'username', 'website']
columnsToDisplay = this.displayedColumns.slice()
headings = ['phone', 'email', 'city', 'streetAddress', 'suite', 'zipCode', 'streetAddressLatitude', 'streetAddressLongitude', 'company', 'companyBusinessServices', 'companyCatchphrase']
isChecked = true
reporter: Reporter
constructor(
private reportersService: ReportersService,
private dialog: MatDialog
) { }
ngOnInit(): void {
this.getReportersFromService()
}
getReportersFromService() {
this.loading = true
this.reportersService.getReporters().subscribe(
(reporters: Reporter[]) => {
this.loading = false
this.reporters = reporters
},
(err) => {
this.loading = false
this.reporters = []
console.log(err)
}
)
}
onClick(reporter: Reporter) {
this.reporter = reporter
if (this.isChecked) {
this.dialog.open(ReportersDialogComponent, {
width: '90%',
data: {
reporter: { ...reporter },
headings: this.headings
}
})
}
}
}