使用 ng-bootstrap 的模板解析错误

cod*_*321 1 javascript ng-bootstrap angular

我收到错误

Uncaught Error: Template parse errors:
There is no directive with "exportAs" set to "ngbAccordion" ("
    <p *ngIf="spinner" class="text-center margin-100">Loading...</p>

    <ngb-accordion [ERROR ->]#acc="ngbAccordion" activeIds="ngb-panel-0">
      <ngb-panel title="Simple">
        <ng-template "): ng:///SurveysModule/SurveysComponent.html@4:19
'ngb-panel' is not a known element:
1. If 'ngb-panel' is an Angular component, then verify that it is part of this module.
2. If 'ngb-panel' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("

    <ngb-accordion #acc="ngbAccordion" activeIds="ngb-panel-0">
      [ERROR ->]<ngb-panel title="Simple">
        <ng-template ngbPanelContent>
    <table class="table table-bord"): ng:///SurveysModule/SurveysComponent.html@5:6
'ngb-accordion' is not a known element:
1. If 'ngb-accordion' is an Angular component, then verify that it is part of this module.
2. If 'ngb-accordion' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
    <p *ngIf="spinner" class="text-center margin-100">Loading...</p>
Run Code Online (Sandbox Code Playgroud)

基于此代码

Uncaught Error: Template parse errors:
There is no directive with "exportAs" set to "ngbAccordion" ("
    <p *ngIf="spinner" class="text-center margin-100">Loading...</p>

    <ngb-accordion [ERROR ->]#acc="ngbAccordion" activeIds="ngb-panel-0">
      <ngb-panel title="Simple">
        <ng-template "): ng:///SurveysModule/SurveysComponent.html@4:19
'ngb-panel' is not a known element:
1. If 'ngb-panel' is an Angular component, then verify that it is part of this module.
2. If 'ngb-panel' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("

    <ngb-accordion #acc="ngbAccordion" activeIds="ngb-panel-0">
      [ERROR ->]<ngb-panel title="Simple">
        <ng-template ngbPanelContent>
    <table class="table table-bord"): ng:///SurveysModule/SurveysComponent.html@5:6
'ngb-accordion' is not a known element:
1. If 'ngb-accordion' is an Angular component, then verify that it is part of this module.
2. If 'ngb-accordion' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
    <p *ngIf="spinner" class="text-center margin-100">Loading...</p>
Run Code Online (Sandbox Code Playgroud)

我以为我正确地关注了https://ng-bootstrap.github.io/#/components/accordion/examples

似乎已正确安装并包含在导入中

import {NgbModule} from '@ng-bootstrap/ng-bootstrap';


@NgModule({

    declarations: [
        AppComponent
    ],
    imports: [
        NgbModule,
Run Code Online (Sandbox Code Playgroud)

yur*_*zui 5

角组件模块范围,所以我的建议是进口NgbModuleSurveysModule

import {NgbModule} from '@ng-bootstrap/ng-bootstrap';


@NgModule({
    ...
    imports: [
        NgbModule,
    ]
})
export class SurveysModule {}
Run Code Online (Sandbox Code Playgroud)