anglejs – 角度2 ng测试:’X’不是已知的组件

前端之家收集整理的这篇文章主要介绍了anglejs – 角度2 ng测试:’X’不是已知的组件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用Angular CLI 1.0.0-beta 16创建了一个带有Angular 2.0 RTM的新项目:

ng init

然后跑:

ng生成组件my-new-component

然后跑:

ng测试

得到这个:

  1. 'app-my-new-component' is not a known element:
  2. 1. If 'app-my-new-component' is an Angular component,then verify that it is part of this module.
  3. 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. ("
  4. </h1>
  5. <p>The mean of life is {{answer}}</p>
  6. [ERROR ->]<app-my-new-component></app-my-new-component>"): AppComponent@4:0
  7. Error: Template parse errors:
  8. at TemplateParser.parse (http://localhost:9877/_karma_webpack_/0.bundle.js:8669:19)
  9. at RuntimeCompiler._compileTemplate (http://localhost:9877/_karma_webpack_/0.bundle.js:17854:51)
  10. at http://localhost:9877/_karma_webpack_/0.bundle.js:17777:83
  11. at Set.forEach (native)
  12. at compile (http://localhost:9877/_karma_webpack_/0.bundle.js:17777:47)
  13. at RuntimeCompiler._compileComponents (http://localhost:9877/_karma_webpack_/0.bundle.js:17779:13)
  14. at RuntimeCompiler._compileModuleAndAllComponents (http://localhost:9877/_karma_webpack_/0.bundle.js:17696:37)
  15. at RuntimeCompiler.compileModuleAndAllComponentsSync (http://localhost:9877/_karma_webpack_/0.bundle.js:17684:21)
  16. at TestingCompilerImpl.compileModuleAndAllComponentsSync (http://localhost:9877/_karma_webpack_/0.bundle.js:24662:35)
  17. at TestBed._initIfNeeded (webpack:///home/adam/monctonug/~/@angular/core/bundles/core-testing.umd.js:1059:0 <- src/test.ts:4568:40)

我已经尝试重新排序组件,没有帮助.解决这个问题的正确方法是什么?

我面临同样的问题,结果是测试你需要声明使用的组件:
  1. beforeEach(() => {
  2. TestBed.configureTestingModule({
  3. declarations: [
  4. AppComponent,MyNewComponent
  5. ],});

猜你在找的Angularjs相关文章