javascript - 自定义组件不是 Angular CLI 应用程序中的已知元素
问题描述
我正在考虑使用 Angular CLI 学习 Angular 8。
我在核心模块中添加了两个新组件,然后将其导入到应用程序模块中。
当我尝试在我的应用程序 html 中呈现组件时,控制台中会抛出“未知元素”错误。
我不确定为什么?
这是我的app.module.ts
import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";
import { AppComponent } from "./app.component";
import { NoopAnimationsModule } from "@angular/platform-browser/animations";
import { CoreModule } from "./core/core.module";
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, NoopAnimationsModule, CoreModule],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
我的core.module.ts
import { NgModule } from "@angular/core";
import { CommonModule } from "@angular/common";
import { InputComponent } from "../input/input.component";
import { GraphComponent } from "../graph/graph.component";
@NgModule({
declarations: [InputComponent, GraphComponent],
imports: [CommonModule],
exports: [InputComponent, GraphComponent]
})
export class CoreModule {}
app.component.html
<div>
<InputComponent></InputComponent>
<GraphComponent></GraphComponent>
</div>
以及其中一个自定义组件的示例:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-input',
templateUrl: './input.component.html',
styleUrls: ['./input.component.scss']
})
export class InputComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
解决方案
我刚刚意识到我指的不是具有正确选择器的组件!
我应该在app-input
.app-graph
app.component.html
推荐阅读
- discord - 不和谐.py。如何在“on_raw_reaction_add”函数中等待人的反应?
- java - 我不知道如何解决问题中的这个错误
- python - Python Beautifulsoup 请求变体
- linux - 错误无法执行忍者。我试图执行“/opt/fuchsia/prebuilt/third_party/ninja/linux-arm64/ninja”
- html - a href 样式 如何更改链接
- nginx - 通过 NGINX Kubernetes Ingress 将 HTML 添加到后端响应正文
- python - Python检查dict是否是其他dict的一部分
- django - 在 Django Rest 框架中处理 Paypal 付款/结帐
- python - 当在我的循环中我有空单元格时,我应该如何避免错误“列表索引超出范围”
- python - Python 字典按字母顺序排列 - 我如何按时间顺序排列?