forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 1
/
resource-list.component.ts
38 lines (31 loc) · 1.1 KB
/
resource-list.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
import { Component, HostListener, OnInit } from '@angular/core';
import { PlatformLocation } from '@angular/common';
import { Category } from './resource.model';
import { ResourceService } from './resource.service';
/* tslint:disable:template-accessibility-elements-content */
@Component({
selector: 'aio-resource-list',
templateUrl: 'resource-list.component.html'
})
export class ResourceListComponent implements OnInit {
categories: Category[];
location: string;
scrollPos = 0;
constructor(
location: PlatformLocation,
private resourceService: ResourceService) {
this.location = location.pathname.replace(/^\/+/, '');
}
href(cat: {id: string}) {
return this.location + '#' + cat.id;
}
ngOnInit() {
// Not using async pipe because cats appear twice in template
// No need to unsubscribe because categories observable completes.
this.resourceService.categories.subscribe(cats => this.categories = cats);
}
@HostListener('window:scroll', ['$event.target'])
onScroll(target: any) {
this.scrollPos = target ? target.scrollTop || target.body.scrollTop || 0 : 0;
}
}