当我试图传递方法时,出现了下面的错误消息
onDeleteComment
到另一个组件。
messageId=[对象对象]
错误类型错误:无法读取未定义的属性“text”
消息-item.component.ts
onDeleteComment(messageId: string, comment: Comment) {
/* For debugging purpose only x*/
console.log('messageId = ' + messageId);
console.log('comment.text = ' + comment.text);
//this.commentService.deleteMessageComment(messageId, comment);
}
消息-item.component.html
<div class="component-container" *ngIf="message$ | async as message; else loading">
/* ... */
<div *ngFor="let comment of message.comments">
<app-comments-item
[commentId]="comment"
(deleteComment)="onDeleteComment($event)"
[sourceId]="message._id">
</app-comments-item>
</div>
</div>
注释-item.component.ts
export class CommentsItemComponent implements OnInit {
comment$: Observable<Comment>;
@Input() commentId: string;
@Output() deleteComment = new EventEmitter<{sourceId: string, comment: Comment}>();
@Input() sourceId: string;
/* ... */
}
注释-item.component.html
<div class="component-container" *ngIf="comment$ | async as comment; else loading">
<div class="header-container">
/* ... */
<div class="buttons-container">
<button mat-icon-button type="button" (click)="deleteComment.emit({sourceId: sourceId, comment: comment})">
</button>
</div>
</div>
/* ... */
</div>
如何将注释冒泡到“我的邮件”项组件?
提前谢谢你的帮助。