Permalink
Browse files

Step 10.4: Subscribe to Parties publication

1 parent becb44e commit bab7c9949a09ef938398e90bde302a9c676b732d @kamilkisiela kamilkisiela committed with DAB0mB Sep 22, 2016
Showing with 11 additions and 3 deletions.
  1. +11 −3 client/imports/app/parties/parties-list.component.ts
@@ -1,5 +1,7 @@
-import { Component } from '@angular/core';
+import { Component, OnInit, OnDestroy } from '@angular/core';
import { Observable } from 'rxjs/Observable';
+import { Subscription } from 'rxjs/Subscription';
+import { MeteorObservable } from 'meteor-rxjs';
import { Parties } from '../../../../both/collections/parties.collection';
import { Party } from '../../../../both/models/party.model';
@@ -10,14 +12,20 @@ import template from './parties-list.component.html';
selector: 'parties-list',
template
})
-export class PartiesListComponent {
+export class PartiesListComponent implements OnInit, OnDestroy {
parties: Observable<Party[]>;
+ partiesSub: Subscription;
- constructor() {
+ ngOnInit() {
this.parties = Parties.find({}).zone();
+ this.partiesSub = MeteorObservable.subscribe('parties').subscribe();
}
removeParty(party: Party): void {
Parties.remove(party._id);
}
+
+ ngOnDestroy() {
+ this.partiesSub.unsubscribe();
+ }
}

0 comments on commit bab7c99

Please sign in to comment.