简体   繁体   English

如何在 ng-content 中使用 ngFor 指令?

[英]How can I use an ngFor directive inside ng-content?

I'm trying to display an array of items using an angular material expansion panel and it's not displaying anything.我正在尝试使用 angular 材质扩展面板显示一组项目,但它没有显示任何内容。 I know the expansion panel uses ng-content to project content into the panel component.我知道扩展面板使用 ng-content 将内容投影到面板组件中。 Here's what my template code looks like:这是我的模板代码的样子:

<mat-expansion-panel>
  <mat-expansion-panel-header>
    <mat-panel-title> This is the expansion title </mat-panel-title>
    <mat-panel-description>
      This is a summary of the content
    </mat-panel-description>
  </mat-expansion-panel-header>
  <div *ngFor="let record of records">
    <span class="detail-label">Record ID</span>
    <span class="detail-value">{{ record?.id }}</span>
    <span class="detail-label">Employee Number</span>
    <span class="detail-value">{{ record?.employeeNumber }}</span>
  </div>
</mat-expansion-panel>

I just created a project using this component and it worked.我刚刚使用这个组件创建了一个项目并且它工作正常。 Make sure you have imported the API of the component and material in the correct way.确保您以正确的方式导入了组件和材料的 API。 Check the package.json for Angular Material, along with any necessary dependencies.检查 package.json 以获取 Angular 材料,以及任何必要的依赖项。 In case you have several modules and you have one for the Angular Material components, make sure you have exported the correct modules and then imported the module that contains the rest of the Material components.如果您有多个模块并且有一个用于 Angular 材料组件,请确保您已导出正确的模块,然后导入包含材料组件的 rest 的模块。 If you have more information about the problem it would be very useful如果您有有关该问题的更多信息,那将非常有用

I was able to solve my problem.我能够解决我的问题。 It turned out there was an error with the array of data I was passing in.原来我传入的数据数组有错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM