在AppComponent中,我在HTML代碼中使用了nav組件。用戶(hù)界面看起來(lái)不錯(cuò)。服務(wù)時(shí)沒(méi)有錯(cuò)誤。當(dāng)我查看該應(yīng)用程序時(shí),控制臺(tái)中也沒(méi)有錯(cuò)誤。但是當(dāng)我為我的項(xiàng)目運(yùn)行Karma時(shí),出現(xiàn)了一個(gè)錯(cuò)誤:Failed: Template parse errors: 'app-nav' is not a known element:1. If 'app-nav' is an Angular component, then verify that it is part of this module.2. If 'app-nav' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.在我的app.module.ts中:有:import { NavComponent } from './nav/nav.component';它也在NgModule的聲明部分中@NgModule({ declarations: [ AppComponent, CafeComponent, ModalComponent, NavComponent, NewsFeedComponent ], imports: [ BrowserModule, FormsModule, HttpModule, JsonpModule, ModalModule.forRoot(), ModalModule, NgbModule.forRoot(), BootstrapModalModule, AppRoutingModule ], providers: [], bootstrap: [AppComponent]})我NavComponent在我的AppComponentapp.component.tsimport { Component, ViewContainerRef } from '@angular/core';import { Overlay } from 'angular2-modal';import { Modal } from 'angular2-modal/plugins/bootstrap';import { NavComponent } from './nav/nav.component';@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css']})export class AppComponent { title = 'Angela';}app.component.html<app-nav></app-nav><div class="container-fluid"></div>我已經(jīng)看到了類(lèi)似的問(wèn)題,但是該問(wèn)題的答案表明我們應(yīng)該在具有導(dǎo)出功能的nav組件中添加NgModule,但是這樣做時(shí)會(huì)出現(xiàn)編譯錯(cuò)誤。還有:app.component.spec.tsimport {NavComponent} from './nav/nav.component';import { TestBed, async } from '@angular/core/testing';import { AppComponent } from './app.component';
Angular 2 Karma Test'component-name'不是一個(gè)已知元素
哈士奇WWW
2019-12-27 10:38:37