Angular 添加具有角度的新组件时出错
我从Angular开始,但在添加新组件时遇到问题: 我已经在Angular中启动了一个新项目,带有Angular 添加具有角度的新组件时出错,angular,Angular,我从Angular开始,但在添加新组件时遇到问题: 我已经在Angular中启动了一个新项目,带有ng new toto无错误,然后我添加了一个新组件,带有ng generate component menu无错误,我删除了我的app.component.html中的所有内容,并使用添加了MenuComponent app.module.ts menu.component.ts app.component.html 我的问题是为什么这个简单的东西不起作用 我的错误 错误:模板分析错误: “Men
ng new toto
无错误,然后我添加了一个新组件,带有ng generate component menu
无错误,我删除了我的app.component.html
中的所有内容,并使用添加了MenuComponent
app.module.ts
menu.component.ts
app.component.html
我的问题是为什么这个简单的东西不起作用
我的错误
错误:模板分析错误:
“MenuComponent”不是已知元素:
1.如果“MenuComponent”是角度组件,则验证它是否是此模块的一部分。
2.若要允许任何元素,请将“无错误模式”添加到此组件的“@NgModule.schemas”。(“[错误->]
“”:ng:///AppModule/AppComponent。html@0:0
提前感谢您的帮助我确信菜单组件
的选择器应该是不同的
使用您在菜单.component.ts中的选择器,而不是使用组件名称本身。大概
<app-menu> </app-menu>
我确信菜单组件的选择器应该不同
使用您在菜单.component.ts中的选择器,而不是使用组件名称本身。大概
<app-menu> </app-menu>
你能发布菜单的代码吗。component
?我更新了我的帖子,我添加了menu.component.t你能发布菜单的代码吗?component
?我更新了我的帖子,我添加了menu.component.t确定它与
一起工作,为什么?它不应该与一起工作?好的,它与
一起工作,为什么?它不应该和你一起工作?
<MenuComponent></MenuComponent>
Angular CLI: 6.0.0
Node: 10.0.0
OS: linux x64
Angular: 6.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.0
@angular-devkit/build-angular 0.6.0
@angular-devkit/build-optimizer 0.6.0
@angular-devkit/core 0.6.0
@angular-devkit/schematics 0.6.0
@ngtools/webpack 6.0.0
@schematics/angular 0.6.0
@schematics/update 0.6.0
rxjs 6.1.0
typescript 2.7.2
webpack 4.6.0
Error: Template parse errors:
'MenuComponent' is not a known element:
1. If 'MenuComponent' is an Angular component, then verify that it is part of this module.
2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("[ERROR ->]<MenuComponent></MenuComponent>
"): ng:///AppModule/AppComponent.html@0:0
<app-menu> </app-menu>