Overlapping Issue with Angular Bootstrap Dynamic Dropdown Menu

I'm currently working on creating a dynamic menu using Angular and Bootstrap for Angular. My main issue right now is that the submenus are overlapping each other when displayed on the page.

To tackle this problem, I started off by referring to the examples provided on the "Angular for Bootstrap" page here. I added *ngFor to make the menus dynamic, but I seem to have hit a roadblock with the buttons overlapping. Can anyone offer some guidance on how I can resolve this issue?

<div class="btn-group mr-3" *ngFor="let appMenu of appMenus">
  <div class="btn-group" ngbDropdown role="group" aria-label="Button group with nested dropdown" >
    <button class="btn btn-outline-primary" ngbDropdownToggle>{{ appMenu.appMenuName }}</button>
    <div class="dropdown-menu" *ngFor="let appMenuItem of appMenu.appMenuItemList" ngbDropdownMenu>
      <button ngbDropdownItem [routerLink]="appMenuItem.path">{{ appMenuItem.appMenuItemName }}</button>
    </div>
  </div>
</div>

Your help would be greatly appreciated. Thank you in advance.

Answer №1

To improve the structure, consider placing the *ngFor directive within the button instead of the div:

<div class="btn-group mr-3">
  <div class="btn-group" ngbDropdown role="group" aria-label="Button group with nested dropdown" >
    <button class="btn btn-outline-primary" ngbDropdownToggle
      *ngFor="let appMenu of appMenus">
      {{ appMenu.appMenuName }}
    </button>

    <div class="dropdown-menu" ngbDropdownMenu>
      <button 
        *ngFor="let appMenuItem of appMenu.appMenuItemList" 
        ngbDropdownItem [routerLink]="appMenuItem.path">
        {{ appMenuItem.appMenuItemName }}
      </button>
    </div>
  </div>
</div>

The issue might be due to having the loop around ngbDropdownMenu in that div, causing it to generate multiple menus with one item each and associating them all with the same div element.

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

Experiencing difficulties with managing immutable state within ngrx framework

Hi there, I'm currently exploring ngrx and trying to implement immutable state management. However, I've run into some issues with getting it to work properly. Below is the reducer I am working with: https://stackblitz.com/edit/brewbrut?file=src ...

Tips on creating a responsive div element within the viewport?

I have a variety of nested div elements within a parent div, set up like this: #mycontent > div { width: 14.28%; } <div id="myheader">some header content</div> <div class="container" id="mycontent"> <div class="outerdiv" id= ...

React Application not reflecting recent modifications made to class

My current project involves creating a transparent navigation bar that changes its background and text color as the user scrolls. Utilizing TailwindCSS for styling in my React application, I have successfully implemented the functionality. // src/componen ...

How can EJS variables be utilized within HTML input fields?

I am facing an issue while trying to use a checkbox to redirect selected users to a new page. I am looking for a solution on how this can be achieved, especially when using mongodb to store the information. Below is my current code snippet: Firstly, I ren ...

Angular is generating local caches of NPM packages within the designated .angular folder

Is there a way to turn off the caching in the main Angular project directory? I noticed this issue after setting up NVM last week. ...

Error: The code is unable to access the '0' property of an undefined variable, but it is functioning properly

I am working with two arrays in my code: bookingHistory: Booking[] = []; currentBookings: any[] = []; Both arrays are populated later in the code. The bookingHistory array consists of instances of Booking, while currentBookings contains arrays of Booking ...

What is the mechanism behind image pasting in Firefox's imgur integration?

Start by launching an image editing software and make a copy of any desired image. Avoid copying directly from a web browser as I will explain the reason later on. Navigate to "http://imgur.com" using Firefox. To paste the copied image, simply press Ctrl+V ...

Improving Efficiency in Angular 2 for Managing a High Volume of Items

Imagine a scenario where I have created a component that showcases a list of items. export class ListComponent implements OnInit{ public list:any; constructor(private _ls: ListService) {} ngOnInit() { this._ls.listLoad().subscribe((data ...

Creating a pop-up modal in an Angular2 application that incorporates a child

Can anyone help me figure out how to use Ng Bootstrap Modal with a child component as the modal body? I'm unsure of the best way to achieve this... export class ParentComponent { @ViewChild("modal") private engineModal: TemplateRef<any>; ...

Combine form data from a reactive form into a string using interpolation

Currently, I am working with an object that has a string property embedded within it. The string in this property contains interpolation elements. For my user interface, I have implemented a reactive form with an input field. My goal is to display the ent ...

Issue observed with the functionality of checkAll and uncheckAll after a user interacts with a single checkbox

After completing an Angular course on Udemy, I decided to implement a custom checkbox in my Angular app. However, I encountered an issue where the UI was not updating properly when using checkAll and uncheckAll functions after the user interacted with an i ...

What is the correct way to set up child page routes with query parameters in the app-routing.module.ts file for Angular?

const routes: Routes = [ { path: '', component: DraftAnalysisHomeComponent }, { path: 'nfldraftanalysis', component: DraftAnalysisHomeComponent }, { path: 'nfldraftanalysis/averagegrades', component: AverageGrade ...

Ways to change the CSS styling of the placeholder attribute within a textarea or input field tag

I am currently working on adjusting the font size of the text within the placeholder attribute of a textarea element. While I have been successful in achieving this using vanilla CSS, I have encountered difficulties when trying to implement the same concep ...

Creating a mind map: A step-by-step guide

I'm currently developing an algorithm to create a mind map. The key focus is on organizing the nodes intelligently to prevent any overlap and ensure a visually pleasing layout. Take a look at this snapshot (from MindNode) as an example: Any suggestio ...

Is there a way for me to enable the user to easily download the HTML file?

Is there a way to create an Invoice in HTML rather than a PDF-file and provide the user with an easy download link for the HTML-file? When I simply link to the HTML file, it only seems to be "temporarily downloaded" and viewed in the user's web brows ...

Surprising spacing found between CSS header elements

As I am in the process of redesigning a website, I have encountered an issue with certain elements in the header section. Specifically, the header consists of a logo, some text, and a navigation bar. There seems to be a thick gap between the bottom of the ...

Modify the code to use a BehaviorSubject subscribing to an Observable

Currently, I am in the process of learning Angular2 and RxJS by studying someone else's application. The application consists of two modules: asObservable.ts export function asObservable(subject: Subject) { return new Observable(fn => subject ...

There is an issue with my HTML due to a MIME type error

I am currently facing an issue with my project. I have developed a node js server and now I want to display an HTML file that includes a Vue script loading data using another method written in a separate JS file. However, when I attempt to load the HTML f ...

Prevent overlapping of range sliders in HTML and CSS

I have designed a range slider with two buttons, but they are overlapping each other. I want to ensure that they do not cross over one another - where the value of the first button should be equal to the minimum value of the second button, and the maximum ...

Issues with the alignment of columns using Bootstrap framework

I've created a design in Photoshop using the Bootstrap 12-column guide, but when I try to implement it using Bootstrap, the results are completely off. https://i.stack.imgur.com/vQwOt.png Here's my HTML code: <!DOCTYPE html> <html lan ...