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

时间:2017-04-08 03:48:41

标签: angular firebase



     <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>
&#13;
&#13;
&#13;

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

我怎样才能使用这个数组?

  

未处理的Promise拒绝:模板解析错误:TypeError:不能   阅读财产&to; toperCase&#39;未定义的(&#34; {{   (currentPlatformProfile | async)}}                                              ] * ngFor =&#34;让平台{{(currentPlatformProfile | async)}}&#34;&gt;                               {{plat&#34;):ng:///AppModule/ProfilecreateComponent.html@130:24无法绑定到   &#39; * ngFor&#39;因为它不是'tr&#39;

的已知属性      
    

块引用

  

2 个答案:

答案 0 :(得分:1)

你有这个吗?

<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)}}"

因为您无法在角度语法

中使用interpolation syntax ({{}})

答案 1 :(得分:0)

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

会解决这个问题