diff --git a/src/app/article/comment/comments.component.ts b/src/app/article/comment/comments.component.ts index 49b99d0..ed5dc4c 100644 --- a/src/app/article/comment/comments.component.ts +++ b/src/app/article/comment/comments.component.ts @@ -8,13 +8,17 @@ import { CommentComponent } from "./comment.component"; templateUrl: 'app/article/comment/comments.html', directives: [PostCommentComponent, CommentComponent] }) -@Inject(CommentService) +@Inject(CommentService, "$rootScope") export class CommentsComponent { - comments: noosfero.Comment[]; + comments: noosfero.Comment[] = []; @Input() article: noosfero.Article; - constructor(private commentService: CommentService) { } + constructor(private commentService: CommentService, private $rootScope: ng.IScope) { + $rootScope.$on("comment.received", (event: ng.IAngularEvent, comment: noosfero.Comment) => { + this.comments.push(comment); + }); + } ngOnInit() { this.commentService.getByArticle(this.article).then((result: noosfero.RestResult) => { diff --git a/src/app/article/comment/post-comment.component.ts b/src/app/article/comment/post-comment.component.ts index 1992ac7..1c36415 100644 --- a/src/app/article/comment/post-comment.component.ts +++ b/src/app/article/comment/post-comment.component.ts @@ -6,7 +6,7 @@ import { NotificationService } from "../../shared/services/notification.service" selector: 'post-comment', templateUrl: 'app/article/comment/post-comment.html' }) -@Inject(CommentService, NotificationService) +@Inject(CommentService, NotificationService, "$rootScope") export class PostCommentComponent { @Input() article: noosfero.Article; @@ -14,13 +14,14 @@ export class PostCommentComponent { @Input() replyOf: noosfero.Comment; - constructor(private commentService: CommentService, private notificationService: NotificationService) { } + constructor(private commentService: CommentService, private notificationService: NotificationService, private $rootScope: ng.IScope) { } save() { if (this.replyOf) { this.comment.reply_of_id = this.replyOf.id; } this.commentService.createInArticle(this.article, this.comment).then(() => { + this.$rootScope.$emit("comment.received", this.comment); this.notificationService.success({ title: "Good job!", message: "Comment saved!" }); }); } -- libgit2 0.21.2