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

标签 javascript angular ng-bootstrap

我遇到了错误

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>

基于这段代码

  <section>
    <p *ngIf="spinner" class="text-center margin-100">Loading...</p>

    <ngb-accordion #acc="ngbAccordion" activeIds="ngb-panel-0">
      <ngb-panel title="Simple">
        <ng-template ngbPanelContent>
    <table class="table table-bordered" *ngIf="surveyFormData.length">
        <thead>
        <tr>
            <th scope="col">Form Type</th>
            <th scope="col" class="width-110">Registry Type</th>
            <th scope="col" class="width-70">Version</th>
            <th scope="col" class="width-150">Published Status</th>
            <th scope="col" class="width-100">Active Status</th>
            <th scope="col" class="width-260 text-center">Actions</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let form of surveyFormData">
            <th scope="row">{{ form.FormType }}</th>
            <th scope="row">{{form.RegistryID | registryType}}</th>
            <th scope="row">{{form.Version }}</th>
            <th scope="row">{{form.IsPublished ? 'Published' : 'Unpublished'}}</th>
            <th scope="row">{{form.IsActive ? 'Active' : 'Inactive'}}</th>
            <td class="text-nowrap">
                <a href="javascript:;" (click)="exportSpecs(form)" title="Export Specs" class="record-action">
                    <i class="material-icons">input</i>
                    <span>Export Specs</span>
                </a>
                <a href="javascript:;" (click)="publishForm(form)" title="Publish" class="record-action" [class.disabled]="form.IsPublished">
                    <i class="material-icons">publish</i>
                    <span>Publish</span>
                </a>

                <a href="javascript:;" (click)="confirmFormActivation(form)" title="Activate" class="record-action" [class.disabled]="form.IsActive">
                    <i class="material-icons">toggle_on</i>
                    <span>Activate</span>
                </a>

                <a routerLink="/records/playground/{{form.FormType}}/{{form.Version}}" title="View form in Playground"
                   class="record-action">
                    <i class="material-icons">visibility</i>
                    <span>View</span>
                </a>
                <a routerLink="/survey-builder/{{form.FormType}}/{{form.RegistryID}}/{{form.Version}}"
                   title="Edit Survey" class="record-action">
                    <i class="material-icons">create</i>
                    <span>Edit</span>
                </a>
            </td>
        </tr>
        </tbody>
    </table>
  </ng-template>
</ngb-panel>
</ngb-accordion>

</section>

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

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

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


@NgModule({

    declarations: [
        AppComponent
    ],
    imports: [
        NgbModule,

最佳答案

Angular 组件是模块范围的,所以我的建议是在 SurveysModule 中导入 NgbModule

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


@NgModule({
    ...
    imports: [
        NgbModule,
    ]
})
export class SurveysModule {}

关于javascript - 使用 ng-bootstrap 模板解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55619440/

相关文章:

javascript - 如何使用JavaScript在 's:radio'中设置 's:textarea'按钮的选定值?

javascript - 使用CSS向javascript添加动画

javascript - 不确定这个 JavaScript "undefined"检查有什么问题

css - 根据 Angular 2 表单中分配的验证器标记必填字段的标签

angular - 与 react-query for angular 类似的库

Angular:如何将输入集中在 ngbDropdown 菜单中?

javascript - 如何在 javascript 或 jquery 中调用对象内部的变量或属性

javascript - 处理有效的模态解雇和真正的异常

Angular 5 模型绑定(bind)不适用于 ng-bootstrap 日期选择器弹出窗口

Angular 2 Http 提供者的可观察订阅未触发