Rya*_*P13 -2 javascript components angular-cli angular
我正在考虑使用 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 {}
Run Code Online (Sandbox Code Playgroud)
我的 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 {}
Run Code Online (Sandbox Code Playgroud)
app.component.html
<div>
<InputComponent></InputComponent>
<GraphComponent></GraphComponent>
</div>
Run Code Online (Sandbox Code Playgroud)
以及自定义组件之一的示例:
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() {
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
119 次 |
| 最近记录: |