Project

General

Profile

« Previous | Next » 

Revision 60843

Added the new methodology page

View differences:

methodology.component.ts
1
import { Component, ViewEncapsulation } from '@angular/core';
1
import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
2
import { ActivatedRoute } from '@angular/router';
3
import { Subscription } from 'rxjs';
2 4

  
3 5
@Component({
4 6
  selector: 'app-methodology',
......
7 9
  encapsulation: ViewEncapsulation.None
8 10
})
9 11

  
10
export class MethodologyPageComponent {
12
export class MethodologyPageComponent implements OnInit, OnDestroy {
13

  
14
  private subscriptions: any[] = [];
15

  
16
  constructor(private route: ActivatedRoute) {
17
  }
18

  
19
  ngOnInit(): void {
20
    this.subscriptions.push(this.route.fragment.subscribe(fragment => {
21
      setTimeout(() => {
22
        this.goTo(fragment);
23
      }, 100);
24
    }));
25
  }
26

  
27
  goTo(id: string) {
28
    const yOffset = -100;
29
    const element = document.getElementById(id);
30
    if (element) {
31
      const y = element.getBoundingClientRect().top + window.pageYOffset + yOffset;
32
      window.scrollTo({top: y, behavior: 'smooth'});
33
    }
34
  }
35

  
36
  ngOnDestroy(): void {
37
    this.subscriptions.forEach(subscription => {
38
      if (subscription instanceof Subscription) {
39
        subscription.unsubscribe();
40
      }
41
    });
42
  }
11 43
}

Also available in: Unified diff