要在Angular中显示所有评论,可以使用ngFor指令来循环遍历评论数组,并使用插值表达式来显示每个评论的内容。
首先,在组件类中定义一个评论数组,如下所示:
comments: string[] = ['评论1', '评论2', '评论3'];
然后,在组件的HTML模板中使用ngFor指令来循环遍历评论数组,并使用插值表达式来显示每个评论的内容,如下所示:
{{ comment }}
完整的组件代码示例如下:
import { Component } from '@angular/core';
@Component({
selector: 'app-comments',
template: `
{{ comment }}
`
})
export class CommentsComponent {
comments: string[] = ['评论1', '评论2', '评论3'];
}
将该组件添加到您的应用程序中,然后在页面上就会显示出所有评论。