Guest User

Untitled

a guest
Dec 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import {
  2. Component,
  3. OnInit,
  4. ɵmarkDirty as markDirty,
  5. OnDestroy
  6. } from '@angular/core';
  7. import { CounterService } from './counter.service';
  8. import { Subscription } from 'rxjs';
  9.  
  10. @Component({
  11. selector: 'app-counter',
  12. templateUrl: './counter.component.html',
  13. styleUrls: ['./counter.component.css']
  14. })
  15. export class CounterComponent implements OnInit, OnDestroy {
  16. counter = 0;
  17. subscription = new Subscription();
  18.  
  19. constructor(private counterService: CounterService) {}
  20.  
  21. ngOnInit() {
  22. this.subscription.add(
  23. this.counterService.getCounter().subscribe(c => {
  24. this.counter = c;
  25. markDirty(this);
  26. })
  27. );
  28. }
  29.  
  30. ngOnDestroy() {
  31. this.subscription.unsubscribe();
  32. }
  33.  
  34. increment() {
  35. this.counterService.increment();
  36. }
  37. }
Add Comment
Please, Sign In to add comment