-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathmerch-display.component.ts
46 lines (38 loc) · 1.17 KB
/
merch-display.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
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Location } from '@angular/common';
import { Merch } from '../data/merch';
import { MerchService } from '../data/merch.service';
@Component({
selector: 'app-merch-display',
templateUrl: './merch-display.component.html',
styleUrls: ['./merch-display.component.scss'],
})
export class MerchDisplayComponent implements OnInit {
merch: Merch[] = [];
private _serviceWorker: ServiceWorker|null = null;
constructor(
private route: ActivatedRoute,
private merchService: MerchService,
private location: Location
) {}
ngOnInit(): void {
navigator.serviceWorker.ready.then( registration => {
this._serviceWorker = registration.active;
});
this.route.params.subscribe((routeParams) => {
this.getMerch(routeParams.category);
if (this._serviceWorker) {
this._serviceWorker.postMessage({ page: routeParams.category });
}
});
}
getMerch(category: string): void {
this.merchService
.getMerchList(category)
.then((merch) => (this.merch = merch));
}
goBack(): void {
this.location.back();
}
}