angular - 错误 Angular 13 : ngForOf not used by any directive. ..无法绑定(bind)到 'ngForOf'

标签 angular typescript visual-studio-code angular13

我收到此错误

Property binding ngForOf not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". > 

Can't bind to 'ngForOf' since it isn't a known property of 'a'

我已经导入了所有必需的模块:CommonModuleBrowserModuleReactiveFormsModule

app.module.ts:

import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { RecipesComponent } from './components/recipes/recipes.component';
import { RecipeListComponent } from './components/recipes/recipe-list/recipe-list.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';

@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent,
    RecipesComponent,
    RecipeListComponent,
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule,
    ReactiveFormsModule,
    CommonModule,
  ],
  providers: [],
  bootstrap: [AppComponent],
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule { }

食谱列表.component.ts:

<div class="row">
  <div class="col-xs-12">
    <a href="#" class="list-group-item clearfix" *ngFor="let recipe of recipes"> // error ngFor
      <div class="pull-left">
        <h4 class="list-group-item-heading"> {{ recipe.name}} </h4>
      </div>
      <span class="pull-right">
        <img [src]="recipe.imagePath" alt=" {{recipe.name}} " srcset="" class="img-responsive" style="max-height: 50px">
      </span>
    </a>
    <app-recipe-item></app-recipe-item>
  </div>
</div>

我正在使用 Angular v13.1.1/Node v16.13.1/VSCode v1.63.2

screen of my error

最佳答案

禁用 Visual Studio 扩展“Angular Language Service”解决了该问题。

关于angular - 错误 Angular 13 : ngForOf not used by any directive. ..无法绑定(bind)到 'ngForOf',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70425548/

相关文章:

angular - 如何将搜索参数传递给 URL?

javascript - 在 typescript 中使用 underscore.js "debounce"函数

flutter - 如何解决 "Execution failed for task ' :app:compileFlutterBuildDebug'."

visual-studio-code - VS Code 设置中的变量,如何?

angular - 使用 Observables 组合 View 模型

angular - (Angular 5) 错误 : control. registerOnChange 不是函数

javascript - 如何用 Protractor 选择组件元素?

dart - 为什么标签缩进在 VSCode 中不一致? ( Dart 语言)

angular - 垫日期开始日期结束日期验证 Angular 8

javascript - Angular - 如果表单 block 处于焦点状态,则显示输入