Javascript *ngFor不迭代数组
我已经创建了一系列贴子,它们的标题和内容都是适当的 当我使用*ngFor显示它时,不会显示任何内容 这是组件的ts文件的代码Javascript *ngFor不迭代数组,javascript,angular,Javascript,Angular,我已经创建了一系列贴子,它们的标题和内容都是适当的 当我使用*ngFor显示它时,不会显示任何内容 这是组件的ts文件的代码 posts = [ { title: 'first', content: '...' }, { title: 'second', content: '...' } ] 这行代码位于全局视图app.component.html <app-mon-post *ngFor="let post of posts">{{ post.title }
posts = [
{
title: 'first',
content: '...'
},
{
title: 'second',
content: '...'
}
]
这行代码位于全局视图app.component.html
<app-mon-post *ngFor="let post of posts">{{ post.title }} </app-mon-post>
{{post.title}
我想问题不是由*ngFor
指令引起的,而是由
元素引起的。请尝试使用标准HTML标记测试循环:
<ul>
<li *ngFor="let post of posts">{{ post.title }}</li>
</ul>
- {{post.title}
请注意,
等自定义元素的内容仅在以下情况下可见:
- 浏览器不知道该元素
- 元素有一些代码来显示它。在角度组件中,通常使用
输入变量来引用内容@ContentChild