为什么我的 ngFor 在异步数组中失败



     <div class="panel-body">
         {{ (currentPlatformProfile | async)?.length }} <!-- line 1 -->
         <table>
             <tr *ngFor="let platform of {{(currentPlatformProfile | async)}}">
                     <td>{{platform.infoPlatform}}</td>
                     <td>{{platform.infoGameId}}</td>
                     <td>{{platform.infoChannel}}</td>
             </tr>
         </table> 
 </div>

我的 html 代码在代码段中,实际上第 1 行工作正常,但在 ngFor 中它失败了

如何使用此数组?

未处理的承诺拒绝:模板分析错误:类型错误:无法 读取未定义的属性"到大写"(" {{ (currentPlatformProfile | async( }} ]*ngFor="let platform of {{(currentPlatformProfile | async(}}"> {{plat"(: ng:///AppModule/ProfilecreateComponent.html@130:24 无法绑定到 "*ngFor",因为它不是"tr"的已知属性。

块引用

你有这个吗?

<tr *ngFor="let platform of currentPlatformProfile">
         <td>{{platform?.infoPlatform}}</td>
         <td>{{platform?.infoGameId}}</td>
         <td>{{platform?.infoChannel}}</td>
 </tr>

同样在类中,在定义 时分配currentPlatformProfile = [],并在模板中使用safe operator (?)以避免错误。

不工作为什么? *ngFor="let platform of {{(currentPlatformProfile | async)}}"

因为您不能在 Angular 语法中使用interpolation syntax ({{}})

<tr *ngFor="let platform of currentPlatformProfile | async">

会解决这个问题

最新更新