簡體   English   中英

錯誤:模板解析錯誤:無法綁定到“ ngForOf”,因為它不是“模板”的已知屬性

[英]Error: Template parse errors: Can't bind to 'ngForOf' since it isn't a known property of 'template'

我正在嘗試使用HTML標記構建表並在標題中出現錯誤。

這是模板:

<template ngfor let-log [ngForOf]="logs">
  <tr>
    <td [lgStatus]="log.level" class="ion-record"></td>
    <td>{{log.timestamp | date:'medium'}}</td>
    <td>{{log.source}}</td>
    <td>{{log.message}}</td>
  </tr>
  <tr>
    <td colSpan="4">{{log.detailedMessage}}</td>
  </tr>
</template>

我檢查了幾個線程,並正確導入了app.module.ts中的BrowserModule和與此模板相關的組件中的CommonModule。

我看不到我做錯了什么:(

在此先感謝您的幫助。 嗶嘰。

確切的語法將是ngFor而不是ngfor因此請使用以下代碼-

<template ngFor let-log [ngForOf]="logs">

欲了解更多類型,請點擊這里

<template ngfor let-log [ngForOf]="logs">

必須

<template ngFor let-log [ngForOf]="logs">
            ^

您可以使用<ng-container>而不是<template>來使用更常見的語法

<ng-container *ngFor="let log of logs">

有一個小錯字,

<template ngFor let-log [ngForOf]="logs">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM