gpt4 book ai didi

typescript - NullInjectorError : StaticInjectorError(BootModule)[BsDropdownDirective -> AnimationBuilder]: NullInjectorError: No provider for AnimationBuilder

转载 作者:行者123 更新时间:2023-12-03 16:22:22 26 4
gpt4 key购买 nike

我正在使用 Angular 8 和 ngx-bootstrap 的 5.3.2 版,我将实现一个导航栏,但我遇到了一个问题:“NullInjectorError: StaticInjectorError(BootModule)”为每个添加的 ngx-bootstrap 模块

app.component.html

<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" (click)="isCollapsed = !isCollapsed" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>

<div class="collapse navbar-collapse" [collapse]=isCollapsed>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
<li><a href="#">Link</a></li>
<li class="dropdown" dropdown>
<a href="#" dropdownToggle class="dropdown-toggle">Dropdown <span class="caret"></span></a>
<ul *dropdownMenu class="dropdown-menu" role="menu">
<li role="menuitem"><a class="dropdown-item" href="#">Action</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown" dropdown>
<a href="#" dropdownToggle class="dropdown-toggle">Dropdown <span class="caret"></span></a>
<ul *dropdownMenu class="dropdown-menu" role="menu">
<li role="menuitem"><a class="dropdown-item" href="#">Action</a></li>
<li role="menuitem"><a class="dropdown-item" href="#">Another action</a></li>
<li role="menuitem"><a class="dropdown-item" href="#">Something else here</a></li>
<li class="divider dropdown-divider"></li>
<li role="menuitem"><a class="dropdown-item" href="#">Separated link</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>


app.component.ts
isCollapsed = true;
和 app.module.ts
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app.routing';
import { CommonModule } from '@angular/common';
import { NgbAccordionModule } from '@ng-bootstrap/ng-bootstrap';
import { CollapseModule, BsDropdownModule } from 'ngx-bootstrap';


@NgModule({
imports: [
CommonModule,
FormsModule,
AppRoutingModule,
HttpClientModule,
NgbAccordionModule,
CollapseModule.forRoot(),
BsDropdownModule.forRoot()
],
declarations: [
AppComponent
],
bootstrap: [AppComponent]
})
export class AppModule {}

最佳答案

  • 在 AppModule 中导入 BrowserAnimationsModule 和 BrowserModule。
  • 并且还使用共享模块来导入“CommonModule”。创建一个新模块
    如下。

  • shared.module.ts


    import { CommonModule } from '@angular/common';
    import { NgModule } from '@angular/core';

    @NgModule({
    imports: [CommonModule],
    exports: [CommonModule],
    declarations: []
    })
    export class SharedModule {}

    app.module.ts


    import { NgModule } from '@angular/core';
    import { FormsModule } from '@angular/forms';
    import { AppComponent } from './app.component';
    import { AppRoutingModule } from './app.routing';
    import { NgbAccordionModule } from '@ng-bootstrap/ng-bootstrap';
    import { CollapseModule, BsDropdownModule } from 'ngx-bootstrap';
    import { BrowserModule } from '@angular/platform-browser';
    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    import { SharedModule } from './shared.module';

    @NgModule({
    imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    AppRoutingModule,
    HttpClientModule,
    NgbAccordionModule,
    CollapseModule.forRoot(),
    BsDropdownModule.forRoot(),
    SharedModule
    ],
    declarations: [
    AppComponent
    ],
    bootstrap: [AppComponent]
    })
    export class AppModule {}

    关于typescript - NullInjectorError : StaticInjectorError(BootModule)[BsDropdownDirective -> AnimationBuilder]: NullInjectorError: No provider for AnimationBuilder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59684236/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com