【发布时间】:2021-05-29 22:22:46
【问题描述】:
所以代码很简单,我有一个组件,我想在其中呈现信息(如果存在),当组件不存在时我得到错误。
所以 post-list.component.html 看起来像这样:
<mat-expansion-panel *ngFor="let post of posts">
<mat-expansion-panel-header>
<mat-panel-title>
{{ post.title }}
</mat-panel-title>
<!-- <mat-panel-description>
{{post.description}}
</mat-panel-description> -->
</mat-expansion-panel-header>
<p>{{ post.content }}</p>
</mat-expansion-panel>
</mat-accordion>
<p *ngIf="posts.length >= 0">No posts added yet</p>
post-list.components.ts 看起来像这样>
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-post-list',
templateUrl: './post-list.component.html',
styleUrls: ['./post-list.component.css'],
})
export class PostListComponent implements OnInit {
constructor() {}
posts = [];
ngOnInit(): void {}
}
我收到此错误: Error image
【问题讨论】:
标签: javascript angular mean-stack