亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Angular 2 Karma Test'component-name'不是一個已知元素

Angular 2 Karma Test'component-name'不是一個已知元素

在AppComponent中,我在HTML代碼中使用了nav組件。用戶界面看起來不錯。服務時沒有錯誤。當我查看該應用程序時,控制臺中也沒有錯誤。但是當我為我的項目運行Karma時,出現了一個錯誤: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>我已經看到了類似的問題,但是該問題的答案表明我們應該在具有導出功能的nav組件中添加NgModule,但是這樣做時會出現編譯錯誤。還有:app.component.spec.tsimport {NavComponent} from './nav/nav.component';import { TestBed, async } from '@angular/core/testing';import { AppComponent } from './app.component';
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 1032 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號