Positioning dropup and dropdowns in ng-bootstrap on a single page

Is it possible to have both dropdown and dropup options on the same page using ng-bootstrap?

I attempted to implement the code provided in the ng-bootstrap documentation, but it only allows for a global configuration of dropdowns. I specifically need to display both dropdown and dropup menus on the same page. My project is based on Angular 8.

import {Component} from '@angular/core';
import {NgbDropdownConfig} from '@ng-bootstrap/ng-bootstrap';

@Component({
  selector: 'ngbd-dropdown-config',
  templateUrl: './dropdown-config.html',
  providers: [NgbDropdownConfig] // add NgbDropdownConfig to the component providers
})
export class NgbdDropdownConfig {
  constructor(config: NgbDropdownConfig) {
    // customize default values of dropdowns used by this component tree
    config.placement = 'top-left';
    config.autoClose = false;
  }
}


<div ngbDropdown>
    <button class="btn btn-secondary" type="button" id="dropDownMenuButton" ngbDropdownToggle>
      Dropup Menu
    </button>
    <div class="dropdown-menu tx-13" ngbDropdownMenu aria-labelledby="dropDownMenuButton">
      <a class="dropdown-item" href="#">Action</a>
      <a class="dropdown-item" href="#">Another action</a>
      <a class="dropdown-item" href="#">Something else here</a>
    </div>
  </div>

  <div class="dropup" ngbDropdown>
    <button class="btn btn-secondary" type="button" id="dropupMenuButton" ngbDropdownToggle>
      Dropup Menu
    </button>
    <div class="dropdown-menu tx-13" ngbDropdownMenu aria-labelledby="dropupMenuButton">
      <a class="dropdown-item" href="#">Action</a>
      <a class="dropdown-item" href="#">Another action</a>
      <a class="dropdown-item" href="#">Something else here</a>
    </div>
  </div>

Answer №1

Check out the API documentation. You have the option to directly specify a placement for the NgbDropdown directive, like this:

<div class="dropup" ngbDropdown placement="top-left">
...
</div>

Additionally, here is a helpful guide for NgBootstrap positioning that includes more examples for your reference.

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

Issue with CSS/SASS within a container containing multiple elements

I am experiencing an issue with an image that I have built: box Initially, the image appears to be a box with 4 elements inside. However, when I resize the window, the layout gets distorted. I am unsure which property I am using incorrectly, so I will pr ...

unable to locate the custom npm package within my service

There is a similar inquiry posted here: My custom NPM Package is not found, but unfortunately, the solution provided did not fix my issue. I am encountering an error stating: "Could not find a declaration file for module '@dc_microurb/common' ...

Having trouble passing parameters in a Node.js express POST request?

Here is the code snippet I am currently working with: const express = require('express'); const app = express(); const bodyParser = require('body-parser'); app.use(bodyParser.urlencoded({ extended: false })); app.post('/rasp&apos ...

Mysterious data organization - transform into an object

As I interact with an API, there is a value that I cannot quite pinpoint. My goal is to transform this string into a JavaScript object, but the process seems complex and confusing. Does anyone have insight on what this data represents and how it can be co ...

Enhance the readability and writability of the properties of JavaScript objects

I'm curious if there's a way to make existing properties of JavaScript objects immutable after they've been assigned. Essentially, what I want is to lock in the current properties of an object but still allow new ones to be added. Can exis ...

script to pause video using jQuery

I have a script that works perfectly, but currently it only stops an instance of a playing video if a new video is started. I want to modify the script so that ALL instances of playing videos are stopped when the function stopAllButMe(); is called. Can s ...

Why did my compilation process fail to include the style files despite compiling all other files successfully?

As English is not my first language, I kindly ask for your understanding with any typing mistakes. I have created a workspace with the image depicted here; Afterwards, I executed "tsc -p ." to compile my files; You can view the generated files here Unf ...

Visualizing connections between elements using SVG from JSON data files

As a newcomer to D3, I am facing challenges in visualizing my json file. My task involves plotting the locations (sites) as circles with their radius determined by the "amount" value. The concept of working with nodes and links is causing me great confusio ...

Unable to retrieve angular HTML content from my standard HTML website

I have a basic HTML website and I am looking to redirect to an Angular website upon clicking a button on the HTML site. Both the HTML website and Angular build are hosted on the same server, Hostinger. The button in question is here: This is the simple HT ...

Ways to print several tabs at once in Angular 4

In my Angular 4 application, I have implemented a feature with 4 tabs ('tab1', 'tab2', 'tab3', 'tab4') on the screen. Each tab corresponds to an Angular component that is dynamically loaded. When a user lands on the ...

Velocity: The initial parameter was not recognized as a property mapping

I've been experimenting with Velocity for animations (without jQuery), but I'm running into an issue where I keep getting this error message: Velocity: First argument ([object HTMLDivElement]) was not a property map, a known action, or a regis ...

"Obtain a DOM element within an Angular directive by using the jQuery find method

When inspecting the DOM, I can see the element anchor tag present but cannot retrieve it using jquery.find(). The console returns a length of 0, preventing me from initializing angular xeditable on that element. angular.module('built.objects') ...

Error: 'discord not defined' encountered when using vscode and powershell

I'm still learning the ropes of javascript, and while attempting to link discord with VSCode (using windows powershell), I'm using the following code: const Discord = require (discord.js) ; const client = new Discord.Client(); clien ...

What is the best way to pause before executing the next npm command until the current command finishes running?

At first glance, creating an 'init' command seems like a straightforward task. However, as I dive deeper into the process, challenges start to surface. The goal is to develop an 'init' command that assists in preparing a cloned repo fo ...

What is the best way to initiate a change event using JavaScript?

I am attempting to enable my 4th checkbox automatically when there is a new value in the textbox (myinput). If the textbox is empty, I want to disable it. Currently, you have to tab out before the change event is triggered. Also, how can I check for an e ...

The CORS policy is blocking Angular Socket.io Node.js because the requested resource does not have the 'Access-Control-Allow-Origin' header present

When trying to access the socket endpoint from my frontend, I encounter this error message: chat:1 Access to XMLHttpRequest at 'http://localhost:3000/socket.io/?EIO=3&transport=polling&t=NOAlAsz' from origin 'http://localhost:4200& ...

Using TypeScript's Array Union Type in defining function parameters

My scenario involves a union type of an Array with specific lengths: [ number ] | [ number, number ] | [ number, number, number, number ] The requirements are for an array with either one element, two elements, or four elements. I am attempting to create ...

Getting the Correct Information from Upload Files in jQuery and PHP

While experimenting with the jquery plugin called jquery.filer, I encountered an issue during file upload on their official website . The returned value I received looked like this: { "files": [ "..\/uploads\/dK079QrL2g.docx" ], "metas": [ ...

The component fails to display during my testing efforts

I am encountering a peculiar issue. In my setup, I am using jasmine 2.0, react 0.13.3, react-router 0.13.3, and various other packages. The problem lies within my test suite where it fails to findRenderedDOMComponentWithTag(). Let me provide a specific exa ...

Avoiding type errors in d3 v5 axis by using Typescript

I am new to TypeScript and I have some code that is functioning perfectly. I believe if I define a type somewhere, d3's generics will come into play? Within my code, I have an xAxis and a yAxis. Both are the same, but D3 seems to have an issue with t ...