angular - 'NgIf' 既不是 'ComponentType' 也不是 'DirectiveType'
问题描述
在一个非常简单的组件中使用 *ngIf 时,我得到标题中的错误。例如,下面的代码和 app.module 会导致:
app.component.html:
<ng-container *ngIf="true">
<div>True</div>
</ng-container>
app.module.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
我对可能导致这种情况的原因感到非常困惑。*ngFor 指令有同样的问题。项目的其余部分直接来自ng new
生成的文件。
"@angular/core": "~11.2.8"
解决方案
损坏或其他奇怪node_modules
的东西很可能是问题的根源。
运行npm ci
可以解决问题。
推荐阅读
- next.js - 是否有样板文件或库可用于使用 Next.js API 路由进行 Hasura 事件和操作处理?
- r - 给定一个命名的字符向量列表,输出一个新列表,其中所有字符向量的唯一元素与原始列表的名称相反
- python - 在 python3.9 类型模块中,NewType 函数允许使用新数据类型创建派生
- ruby-on-rails - 如何解决来自 nylas 的“无法在只读日历上创建事件”的错误?
- sql - 使用 SQL 查询每天自动化元数据库中的仪表板
- python-3.x - 获取在 top.gg 上支持服务器的用户
- python - 有没有办法在不使用双 for 循环的情况下迭代 Python 中的嵌套字典?
- graphics - 通过 R 中边上的概率生成无向图
- sql - 如何在sql语句中同时使用like和in?
- python - 您可以根据特征值在另一个数据框中出现的次数来复制 pandas 数据框中的行吗?