Angular 角度2+;ng测试:';X';不是已知的组件
我使用Angular CLI 1.0.0-beta 16创建了Angular 2.0 RTM新项目:Angular 角度2+;ng测试:';X';不是已知的组件,angular,webpack,angular-cli,Angular,Webpack,Angular Cli,我使用Angular CLI 1.0.0-beta 16创建了Angular 2.0 RTM新项目: ng init 然后跑: ng生成组件我的新组件 然后跑: ng测试 得到这个: 'app-my-new-component' is not a known element: 1. If 'app-my-new-component' is an Angular component, then verify that it is part of this module. 2. If 'app-my
ng init
然后跑:
ng生成组件我的新组件
然后跑:
ng测试
得到这个:
'app-my-new-component' is not a known element:
1. If 'app-my-new-component' is an Angular component, then verify that it is part of this module.
2. If 'app-my-new-component' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. ("
</h1>
<p>The mean of life is {{answer}}</p>
[ERROR ->]<app-my-new-component></app-my-new-component>"): AppComponent@4:0
Error: Template parse errors:
at TemplateParser.parse (http://localhost:9877/_karma_webpack_/0.bundle.js:8669:19)
at RuntimeCompiler._compileTemplate (http://localhost:9877/_karma_webpack_/0.bundle.js:17854:51)
at http://localhost:9877/_karma_webpack_/0.bundle.js:17777:83
at Set.forEach (native)
at compile (http://localhost:9877/_karma_webpack_/0.bundle.js:17777:47)
at RuntimeCompiler._compileComponents (http://localhost:9877/_karma_webpack_/0.bundle.js:17779:13)
at RuntimeCompiler._compileModuleAndAllComponents (http://localhost:9877/_karma_webpack_/0.bundle.js:17696:37)
at RuntimeCompiler.compileModuleAndAllComponentsSync (http://localhost:9877/_karma_webpack_/0.bundle.js:17684:21)
at TestingCompilerImpl.compileModuleAndAllComponentsSync (http://localhost:9877/_karma_webpack_/0.bundle.js:24662:35)
at TestBed._initIfNeeded (webpack:///home/adam/monctonug/~/@angular/core/bundles/core-testing.umd.js:1059:0 <- src/test.ts:4568:40)
“app-my-new-component”不是已知元素:
1.如果“应用程序我的新组件”是角度组件,则验证它是否是此模块的一部分。
2.如果“app my new component”是Web组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到此组件的“@NgModule.SCHEMA”以抑制此消息。("
生命的平均值是{{答案}
[错误->]”:AppComponent@4:0
错误:模板分析错误:
在TemplateParser.parse(http://localhost:9877/_karma_webpack_/0.bundle.js:8669:19)
在运行时编译器上(http://localhost:9877/_karma_webpack_/0.bundle.js:17854:51)
在http://localhost:9877/_karma_webpack_/0.bundle.js:17777:83
at Set.forEach(本机)
编译时(http://localhost:9877/_karma_webpack_/0.bundle.js:17777:47)
在运行时编译器上(http://localhost:9877/_karma_webpack_/0.bundle.js:17779:13)
在运行时编译器上。\编译emoduleandallcomponents(http://localhost:9877/_karma_webpack_/0.bundle.js:17696:37)
在RuntimeCompiler.CompileModule和AllComponents同步(http://localhost:9877/_karma_webpack_/0.bundle.js:17684:21)
在测试CompilerImpl.CompileModule和所有组件时同步(http://localhost:9877/_karma_webpack_/0.bundle.js:24662:35)
在试验台上。如果需要(webpack:///home/adam/monctonug/~/@angular/core/bundles/core testing.umd.js:1059:0I面临着同样的问题,结果证明,对于测试,您也需要声明使用过的组件:
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent,
MyNewComponent
],
});
有相同的问题。我在GitHub上查看了与此错误相关的开放/关闭问题,但没有找到解决方案。我在关于同一问题的另一个问题上提供了此问题的最新答案:这就是问题所在。我有其他问题,但这解决了此问题。我的生活中也有其他问题,这也解决了此问题答案没有修正,但它确实为我解决了这个问题!干得好。花了30分钟我找到了你的答案。谢谢!