我有一个Angular应用程序加载并正常工作但是当我运行Karma进行单元测试时,我收到此错误:
错误:
Failed: Uncaught (in promise): Error: Template parse errors:
'app-appheader' is not a known element:
1. If 'app-appheader' is an Angular component, then verify that it is part of this module.
2. If 'app-appheader' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<app-appheader></app-appheader>
<app-appmenu></app-appmenu>
app.component.html
内容非常简单:
<html>
<app-appheader></app-appheader>
<app-appmenu></app-appmenu>
<app-appsettings></app-appsettings>
<app-appfooter></app-appfooter>
</html>
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { AppheaderComponent } from './components/appheader/appheader.component';
import { AppfooterComponent } from './components/appfooter/appfooter.component';
import { AppmenuComponent } from './components/appmenu/appmenu.component';
import { AppsettingsComponent } from './components/appsettings/appsettings.component';
@NgModule({
declarations: [
AppComponent,
AppheaderComponent,
AppfooterComponent,
AppmenuComponent,
AppsettingsComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [],
bootstrap: [AppComponent],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
})
export class AppModule { }
appheader.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-appheader',
templateUrl: './appheader.component.html',
styleUrls: ['./appheader.component.css']
})
export class AppheaderComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
这是我正在运行的代码正常运行,但是没有通过单元测试...
在这一刻,我通过在spec.ts
文件中实施NO_ERRORS_SCHEMA
来解决问题,但我确信这不是正确的移动方式。
答案 0 :(得分:2)
我通过实施这一行解决了我的问题:
var childFolders = DriveApp.getFolders();
并使用 ng serve 重新启动应用程序。
侨