Utilizing ng-bootstrap within a rebranded module

I'm facing an issue with my nav-bar module that utilizes ng-bootstrap:

import {NgModule, NgZone} from '@angular/core';
import { CommonModule } from '@angular/common';
import {NavigationComponent} from "./components/navigation/navigation.component";
import {NavMenuComponent} from "./components/nav-menu/nav-menu.component";
import {MainMenuComponent} from "./components/main-menu/main-menu.component";
import {NgbModule} from "@ng-bootstrap/ng-bootstrap";

@NgModule({
  imports: [
    CommonModule,
    NgbModule
  ],
  declarations: [
    NavigationComponent,
    NavMenuComponent,
    MainMenuComponent
  ],
  exports: [
    NavigationComponent,
    NavMenuComponent,
    MainMenuComponent,
    CommonModule,
    NgbModule
  ],
  providers: [{ provide: NgZone, useFactory: () => new NgZone({}) }]
})
export class MainNavbarModule { }

The structure of the project includes the nav-bar module in one directory and another directory where it needs to be imported:

  • Main directory
    • App1 (where the nav-bar module is located)
    • App2 (where I need to import it)

This is App2's module:

    import {BrowserModule} from '@angular/platform-browser';
import {NgModule, NgZone} from '@angular/core';
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
import {MainNavbarModule} from '@front-core/src/app/shared/main-navbar.module';
import {AppComponent} from './app.component';
import {AppRoutes} from './app.routes';
import {CommonModule} from '@angular/common';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    NgbModule.forRoot(),
    CommonModule,
    AppRoutes,
    MainNavbarModule
  ],
  bootstrap: [AppComponent]
})
export class AppModule {
}

The path @front-core is specified in tsconfig.app.json like this:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": ".",
    "module": "es2015",
    "types": [],
    "paths": {
      "@front-core/*": ["../../front-core/*"]
    }
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

However, when trying to include this component in the template of App2, an error occurs:

   ERROR Error: StaticInjectorError[NgbDropdownConfig]: 
  StaticInjectorError[NgbDropdownConfig]: 
    NullInjectorError: No provider for NgbDropdownConfig!
    at _NullInjector.get (core.js:993)
    at resolveToken (core.js:1281)
    at tryResolveToken (core.js:1223)
    at StaticInjector.get (core.js:1094)
    at resolveToken (core.js:1281)
    at tryResolveToken (core.js:1223)
    at StaticInjector.get (core.js:1094)
    at resolveNgModuleDep (core.js:10878)
    at NgModuleRef_.get (core.js:12110)
    at resolveDep (core.js:12608)

Answer №1

To properly use any sub modules that utilize ngbmodule, you must include it in the following way:

imports: [NgbModule]

In your main app module, ensure it is declared as follows:

imports: [NgbModule.forRoot()]

Do not export NgbModule in your navbar module. Besides that export, it appears that you have imported it correctly based on the instructions provided earlier. You may want to try removing that export.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Display as selected when the option is chosen

Two APIs are available to retrieve permissions data: one returns a list of all permissions, while the other returns a list of selected permissions. The goal is to display a list of permissions in checkboxes, with a checkmark next to any permissions that ha ...

Retrieving information from a JSON file using JavaScript

My code snippet looks like this: { "badge_sets":{ "1979-revolution_1":{ "versions":{ "1":{ "image_url":"https://static-cdn.jtvnw.net/badges/v1/7833bb6e-d20d-48ff-a58d-67f ...

How can I use jQuery to set the color of every other row in a

I'm facing an issue where I want to use jQuery to set the color of alternate rows in an HTML table. However, every time I add a new row, the color of the entire table switches. Below is the JavaScript code snippet that I am utilizing: var alternate = ...

Convert this JavaScript function into a jQuery function

I currently have this JavaScript function: function removeStyle(parent){ var rmStyle = document.getElementById(parent).getElementsByTagName("a"); for (i=0; i<rmStyle.length; i++){ rmStyle[i].className = ""; } } Since I am now using ...

Restrict the display of items in a unordered list element

Below is my code snippet that limits the number of visible list items in a ul: $wnd.$(el) .find('li:gt(9)') .hide() .end() .append( $wnd.$('<li>+More</li>').click( function(){ $wnd.$(this).nextAl ...

Is it possible to enable unknown keys for multiple schema objects simultaneously using Joi Validation?

I have a multitude of validator files each containing nearly a hundred schema objects. My goal is to validate unknown keys for all of them simultaneously. I've managed to figure out how to do it for a single object, as shown below. Is there a way to a ...

What steps should I take to resolve a 'Missing environment variable' issue in the Sanity platform?

No matter what I've tried, I can't seem to fix the error that keeps occurring. An uncaught error is popping up, saying that the environment variable NEXT_PUBLIC_SANITY_DATASET is missing. http://localhost:3333/static/sanity-5377bc10.js:4605 ...

XML integration with Jplayer is not functioning properly

I'm in the process of setting up Jplayer to work with an XML document so that my client can easily update the playlist. I managed to get it working flawlessly when I manually coded the songs into the JS. Here's my current code: <div class="bo ...

Utilize the standard error handler in Angular 4

In my Angular4 application, I have set up a custom error handler as follows: @Injectable() export class CustomErrorHandler implements ErrorHandler { handleError(error) { switch (error.type) { case 'custom': doTheThing(); defa ...

Retrieving the selected value from an added dropdown list using jQuery

Could someone please guide me on how to retrieve the selected value from an appended select list using jQuery? Any assistance would be greatly appreciated. Thank you in advance. var wrapper1 = $(".column1"); array1 = ["sample1", "sample2", "sample3"]; ...

Transmit data to PHP servers

When the button in my HTML is clicked, it should trigger a query in a PHP file that will display the results. However, the button does not seem to be working as expected. What could be causing this issue? Here is the code I have tried: <?php $reply_ ...

The challenge of default Vuetify styles within a Nuxt environment

Here is my code snippet: <div class="cd-page__details-wrapper"> <v-text-field label="Outlined" placeholder="Outlined" outlined ></v-text-field> </div> Unfortunately, something unexpecte ...

JavaScript Database Operations

I have a script that reads data from a Google Sheet and returns its content. I am looking to save all of this data into a database. var request = gapi.client.sheets.spreadsheets.values.get(params); request.then(function(response) { console.log(respons ...

"My JavaScript code for toggling visibility is not functioning properly. Any suggestions on how to fix

I am currently working on a task that involves showing and hiding container1, but I am confused as to why my code is not functioning properly. The task requirements are as follows: - Clicking on the "Show" button should display container1 - Clicking on the ...

Display a React component according to the user's input

Within the first (parent) div, there is an underlined message stating: "This JSX tag's 'children' prop expects a single child of type 'ReactNode', but multiple children were provided.ts(2746)". import A from './components/A&ap ...

After successfully logging in with the angular2-token package, the Rails 4 API is responding with a 401 unauthorized error

In my current setup, I have a Rails 4 API with the gem Devise Token Auth hosted separately from my Angular 2 frontend application. To handle cross-origin requests, I have configured Rack CORS. Using Angular2-token on my front end, I can successfully sign u ...

Is there a way to display nested object values within an object using VueJs?

I am encountering an issue where my code is not printing out values from an object correctly. The nested objects are displaying the entire object as { propName: value } on the UI. Below is the HTML code: <ul class="o-pf-list"> <li v-for="(v ...

Associate union with interface attributes

Can a union type be transformed into an interface in Typescript? My Desired Outcome If we have a union type A: type A = 'one' | 'two' | 'three'; I want to convert it to interface B: interface B { one: boolean; two ...

Importing Angular Material modules

I've integrated the Angular Material module into my project by updating the material.module.ts file with the following imports: import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { MatT ...

Is it possible for Typescript to provide protection or differentiation based on the presence of a field (undefined / absent) rather than its

Could someone clarify the reason behind why Typescript has the capability to narrow types using the in keyword, but not based on the presence of a non-undefined value? I am in the process of transitioning a significant JavaScript codebase to TypeScript, an ...