Commit 5e8db4bd45b12a5b1a67452418dcb2edbb02b829
1 parent
9d63c8c4
Exists in
master
and in
1 other branch
Emit an event when a comment was created
Showing
2 changed files
with
10 additions
and
5 deletions
Show diff stats
src/app/article/comment/comments.component.ts
... | ... | @@ -8,13 +8,17 @@ import { CommentComponent } from "./comment.component"; |
8 | 8 | templateUrl: 'app/article/comment/comments.html', |
9 | 9 | directives: [PostCommentComponent, CommentComponent] |
10 | 10 | }) |
11 | -@Inject(CommentService) | |
11 | +@Inject(CommentService, "$rootScope") | |
12 | 12 | export class CommentsComponent { |
13 | 13 | |
14 | - comments: noosfero.Comment[]; | |
14 | + comments: noosfero.Comment[] = []; | |
15 | 15 | @Input() article: noosfero.Article; |
16 | 16 | |
17 | - constructor(private commentService: CommentService) { } | |
17 | + constructor(private commentService: CommentService, private $rootScope: ng.IScope) { | |
18 | + $rootScope.$on("comment.received", (event: ng.IAngularEvent, comment: noosfero.Comment) => { | |
19 | + this.comments.push(comment); | |
20 | + }); | |
21 | + } | |
18 | 22 | |
19 | 23 | ngOnInit() { |
20 | 24 | this.commentService.getByArticle(this.article).then((result: noosfero.RestResult<noosfero.Comment[]>) => { | ... | ... |
src/app/article/comment/post-comment.component.ts
... | ... | @@ -6,7 +6,7 @@ import { NotificationService } from "../../shared/services/notification.service" |
6 | 6 | selector: 'post-comment', |
7 | 7 | templateUrl: 'app/article/comment/post-comment.html' |
8 | 8 | }) |
9 | -@Inject(CommentService, NotificationService) | |
9 | +@Inject(CommentService, NotificationService, "$rootScope") | |
10 | 10 | export class PostCommentComponent { |
11 | 11 | |
12 | 12 | @Input() article: noosfero.Article; |
... | ... | @@ -14,13 +14,14 @@ export class PostCommentComponent { |
14 | 14 | |
15 | 15 | @Input() replyOf: noosfero.Comment; |
16 | 16 | |
17 | - constructor(private commentService: CommentService, private notificationService: NotificationService) { } | |
17 | + constructor(private commentService: CommentService, private notificationService: NotificationService, private $rootScope: ng.IScope) { } | |
18 | 18 | |
19 | 19 | save() { |
20 | 20 | if (this.replyOf) { |
21 | 21 | this.comment.reply_of_id = this.replyOf.id; |
22 | 22 | } |
23 | 23 | this.commentService.createInArticle(this.article, this.comment).then(() => { |
24 | + this.$rootScope.$emit("comment.received", this.comment); | |
24 | 25 | this.notificationService.success({ title: "Good job!", message: "Comment saved!" }); |
25 | 26 | }); |
26 | 27 | } | ... | ... |