Home > Software design >  NullInjectorError: No provider for BsDropdownConfig
NullInjectorError: No provider for BsDropdownConfig

Time:10-22

I want to use the ngx-bootstrap dropdown, so i've import the lib in the app.module

BsDropdownModule.forRoot(),

and in my html, i want to try the example found in the documentation

<div  dropdown>
        <button id="button-basic" dropdownToggle type="button" 
                aria-controls="dropdown-basic">
          Button dropdown <span ></span>
        </button>
        <ul id="dropdown-basic" *dropdownMenu 
            role="menu" aria-labelledby="button-basic">
          <li role="menuitem"><a  href="#">Action</a></li>
          <li role="menuitem"><a  href="#">Another action</a></li>
          <li role="menuitem"><a  href="#">Something else here</a></li>
        </ul>
      </div>

And i got this error in the console :

ERROR Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(AppModule)[BsDropdownDirective -> BsDropdownConfig]: 
  StaticInjectorError(Platform: core)[BsDropdownDirective -> BsDropdownConfig]: 
    NullInjectorError: No provider for BsDropdownConfig!
NullInjectorError: StaticInjectorError(AppModule)[BsDropdownDirective -> BsDropdownConfig

i've tried to import the BsDropdownConfig but it not a module.

is there any think that i must import ?

CodePudding user response:

Apparently there is no default config provided by the BsDropdownModule, which is odd, but you can manually provide one, either in the root module injector (in the providers array), or in the component's own injector using

providers: [{ provide: BsDropdownConfig, useValue: { autoClose: true } }]
  • Related