【问题标题】:why my ngFor failed in async array为什么我的 ngFor 在异步数组中失败
【发布时间】:2017-09-03 12:54:15
【问题描述】:

     <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 代码在 sn-p 中,实际上第 1 行工作正常,但在 ngFor 中却失败了

如何使用这个数组?

未处理的承诺拒绝:模板解析错误:TypeError:不能 读取未定义的属性“toUpperCase”(“ {{ (当前平台配置文件|异步)}} ]*ngFor="让平台 {{(currentPlatformProfile | async)}}"> {{plat"): ng:///AppModule/ProfilecreateComponent.html@130:24 无法绑定 '*ngFor' 因为它不是 'tr' 的已知属性。

块引用

【问题讨论】:

    标签: angular firebase


    【解决方案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 ({{}})

    【讨论】:

    • 我已经在下面解决了这个问题,但是你提供了另一种解决方案,谢谢。
    • 欢迎您,我知道您选择哪种解决方案吗?
    • @Pardeep Jain 我应用了我自己回答的以下解决方案,但您的答案肯定是更深层次的。
    • 哦,很好的自我回答,很高兴听到我的回答 :)
    【解决方案2】:
    <tr *ngFor="let platform of currentPlatformProfile | async">
    

    会解决这个问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-28
      • 2021-10-21
      • 2014-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-30
      相关资源
      最近更新 更多