37 lines
844 B
TypeScript
37 lines
844 B
TypeScript
import { Component, OnInit, Input, Output } from '@angular/core';
|
|
|
|
import { CommentService } from '../../services/comment.service';
|
|
|
|
@Component({
|
|
selector: 'ui-comments',
|
|
templateUrl: './comments.ui.html',
|
|
styleUrls: [ './comments.ui.scss' ]
|
|
})
|
|
export class UiComments implements OnInit {
|
|
|
|
comments: any;
|
|
@Input() target: number;
|
|
@Input() parent: number;
|
|
boundRefresh: Function;
|
|
|
|
constructor(private commentService: CommentService) { }
|
|
|
|
ngOnInit(): void {
|
|
this.boundRefresh = this.refresh.bind(this);
|
|
this.refresh();
|
|
}
|
|
|
|
refresh(): void {
|
|
if (this.parent) {
|
|
this.commentService.getParent(this.target, this.parent).subscribe((data) => {
|
|
this.comments = data;
|
|
})
|
|
} else {
|
|
this.commentService.get(this.target).subscribe((data) => {
|
|
this.comments = data;
|
|
})
|
|
}
|
|
}
|
|
|
|
}
|