Skip to content

Commit

Permalink
add unsubscribe in article-comment component
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrohridin committed May 18, 2018
1 parent 615327e commit 366fc97
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/app/article/article-comment.component.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
import { Component, EventEmitter, Input, Output, OnInit } from '@angular/core';
import { Component, EventEmitter, Input, Output, OnInit, OnDestroy } from '@angular/core';

import { Comment, User, UserService } from '../core';
import { Subscription } from 'rxjs/Subscription';

@Component({
selector: 'app-article-comment',
templateUrl: './article-comment.component.html'
})
export class ArticleCommentComponent implements OnInit {
export class ArticleCommentComponent implements OnInit, OnDestroy {
constructor(
private userService: UserService
) {}

private subscription: Subscription;

@Input() comment: Comment;
@Output() deleteComment = new EventEmitter<boolean>();

canModify: boolean;

ngOnInit() {
// Load the current user's data
this.userService.currentUser.subscribe(
this.subscription = this.userService.currentUser.subscribe(
(userData: User) => {
this.canModify = (userData.username === this.comment.author.username);
}
);
}

ngOnDestroy() {
this.subscription.unsubscribe();
}

deleteClicked() {
this.deleteComment.emit(true);
}
Expand Down

0 comments on commit 366fc97

Please sign in to comment.