Click the button to open the drop-down menu-PHP Chinese Network Q&A
Click the button to open the drop-down menu
P粉232409069
P粉232409069 2023-09-04 15:04:13
0
1
529

I am using bootstrap 5 cdn and I want to open the dropdown without clicking on the dropdown.

I use the navigation bar and want to display "drop-down links":

 

In the component I try to do the following but it doesn't work:

export class AppComponent { open() { const dropdown = document.getElementById('test'); dropdown.click(); } }

I did it in stackblitz: test

P粉232409069
P粉232409069

reply all (1)
P粉333186285

Add bootstrap attributes to button:

Link code:https://stackblitz.com/edit/angular-bootstrap-5-dynamic-navbar-77sj13?file=app/app.component.html

It will work, however. Keep in mind that your angular application should control these elements, so mixing external libraries with framework libraries (Angular, Vue, React) will always cause trouble

For this purpose, there are special implementations, for example:https://ng- bootstrap.github.io/#/homeAngle guide

Another option is to use ngIf to show the navigation bar (no animation by default)

Another link:https://stackblitz.com/edit/angular-bootstrap-5-dynamic-navbar-hygpzq?file=app/app.component.html

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!