Answer the question
In order to leave comments, you need to log in
Similar to events in AngularJS2?
There is a simple comment component:
import {Component, Input, OnInit} from 'angular2/core';
export class Comment {
id: number;
text: string;
comments: Comment[];
}
@Component({
selector: 'comment',
template: `
<div>
#{{comment.id}} - {{comment.text}}
<p (click)="commenting = !commenting">Ответить</p>
<textarea *ngIf="commenting"></textarea>
<div class='coms' *ngFor="#com of comment.comments">
<comment [cmnt]="com"></comment>
</div>
</div>
`, directives: [CommentsComponent],
styles: [`.coms {margin-left: 20px} p {margin: 0} textarea {width: 600px; max-width: 100%}`]
})
export class CommentsComponent {
@Input() cmnt: Comment
comment: Comment;
commenting: boolean;
ngOnInit() {
this
this.commenting = true;
if (this.cmnt) this.comment =
this.cmnt;
else
this.comment = <Comment>{ id: 1, text: 'Text', comments: [{ id: 2, text: 'Txt2', comments: [{ id: 2, text: 'Txt2' }, { id: 3, text: 'Txt3' }] }, { id: 3, text: 'Txt3', comments: [{ id: 2, text: 'Txt2' }, { id: 3, text: 'Txt3' }] }] };
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question