• TechQA.

    Bootstrap list activating both menu in angular 13 on selecting

    2.1k views Asked by chethan At 2022-04-08T08:46:24+00:00 08 April 2022 at 08:46 2025-12-21T08:08:51+00:00

    enter image description here

    enter image description here

    <ul class="nav">        
        <li class="nav-item" *ngFor="let menu of menuList">
    
          <a class="nav-link" href="index.html" *ngIf="menu.subMenu?.length<1">
            <i class="icon-grid menu-icon"></i>
            <span class="menu-title">{{menu.title}}</span>
          </a>
    
          <a class="nav-link"  *ngIf="menu.subMenu?.length>0" data-toggle="collapse"
             href="#ui-basic" aria-expanded="false" aria-controls="ui-basic">
            <i class="icon-layout menu-icon"></i>
            <span class="menu-title">{{menu.title}}</span>
            <i class="menu-arrow"></i>
          </a>
          <div class="collapse" id="ui-basic" *ngIf="menu.subMenu?.length>0">
            <ul class="nav flex-column sub-menu">
              <li class="nav-item" *ngFor="let sub of menu.subMenu">
                <a class="nav-link">
                  {{sub.title}}
                </a>
              </li>              
            </ul>
          </div>
        </li>
      </ul>
    
    
       export const SideBarMenu = [
         {
        id: 'dashboard',
        title: 'Dashboard',
        icon: 'icon-grid menu-icon',
        url: '',
      },
      {
        id: 'task',
        title: 'Task',
        icon: 'icon-layout menu-icon',
        url: '',
        subMenu: [
          {
            id: 'task1',
            title: 'Task 1',
            icon: '',
            url: '',
           },
          {
            id: 'task2',
            title: 'Task 2',
            icon: '',
            url: '',
          },
        ],
      },
      {
        id: 'scheduler',
        title: 'Scheduler',
        icon: 'icon-layout menu-icon',
        url: '',
        subMenu: [
          {
            id: 'calendar',
            title: 'Calendar',
            icon: '',
            url: '',
           },
           {
            id: 'scheduler',
            title: 'Scheduler',
            icon: '',
            url: '',
          },
          {
            id: 'orders',
            title: 'Orders',
            icon: '',
            url: '',
           },
           {
            id: 'users',
            title: 'Users',
            icon: '',
            url: '',
           },
           {
            id: 'sales',
            title: 'Sales',
            icon: '',
            url: '',
           },
         ],
       },
     ];
    

    Hi, I have created bootstrap sidebar here if i click on list its activating other menu also (please refer image 2) how to solve this . sorry if you don't understand question please refer image for clarification .

    i am using ngFor loop to display all the sidebar menu if i select any one menu its also activating other menu also please help me to find the solution.

    css angular bootstrap-4 angular13
    Original Q&A
    1

    There are 1 answers

    1
    alin0509 alin0509 On 2022-04-08T10:05:42+00:00 08 April 2022 at 10:05 BEST ANSWER

    You should create unique ids for the menus something like this 'ui-basic'+index

    <ul class="nav">        
        <li class="nav-item" *ngFor="let menu of menuList; let index = index"">
          <a class="nav-link" href="index.html" *ngIf="menu.subMenu?.length<1">
            <i class="icon-grid menu-icon"></i>
            <span class="menu-title">{{menu.title}}</span>
          </a>
          <a class="nav-link"  *ngIf="menu.subMenu?.length>0" data-toggle="collapse"
             href="#ui-basic" aria-expanded="false" [aria-controls]="'ui-basic'+index">
            <i class="icon-layout menu-icon"></i>
            <span class="menu-title">{{menu.title}}</span>
            <i class="menu-arrow"></i>
          </a>
          <div class="collapse" [id]="'ui-basic'+index" *ngIf="menu.subMenu?.length>0">
            <ul class="nav flex-column sub-menu">
              <li class="nav-item" *ngFor="let sub of menu.subMenu">
                <a class="nav-link">
                  {{sub.title}}
                </a>
              </li>              
            </ul>
          </div>
        </li>
      </ul>
    

    Related Questions in CSS

    • How to use custom font during html to pdf conversion?
    • Storing the preferred font-size in localStorage
    • mp4 embedded videos within github pages website not loading
    • Is there any way to glow this bulb image like a real light bulb
    • What can I do to improve my coding on both html and css
    • Uncaught TypeError: google.maps.LatLng is not a constructor at init (script.js:7:13)
    • Bootstrap modal not showing at the desired position on a web page when the screen size is smaller
    • How to increase quality of mathjax output?
    • Hover animation resetting( seemingly reverting back to original CSS and then again to hover)when moving mouse horizontaly accross a part of an element
    • Storing selected language in localStorage
    • How to clip grid cell and provide scroll as well?
    • KeyboardAvoidingView makes a messy the flexbox
    • Rotate an object around another object in javascript
    • Understanding Scroll Anchoring Behavoir
    • how to use only block layout in this css code?

    Related Questions in ANGULAR

    • Firebase link existing user to anonymous account?
    • It doesnt always show all the books on my homepage
    • Google adsense ads.txt status cannot be not found
    • When I navigate to the URL'http://localhost:4200/', it redirects me back
    • Ionic Angular Standalone ion-icon are not showing at all
    • How to make Angular understand that view child is of a specific type, not a general ElementRef?
    • vscode, debug angular, first time, doesn't debug, 2nd time stops at main.js then it's ok
    • How to perform CRUD operations on a static JSON array in Angular? (without API)
    • Ngrx props<>() method in createAction()
    • How to animate rotation of an image inside input control?
    • Detecting click inside and outside of the listening component in Angular
    • Angular - type guard not narrowing types
    • In node_modules file i am getting Angular genric error while using fontawesome in angular12
    • Angular 16 sending null values to API
    • GoogleCloud Error: Not Found The requested URL was not found on this server

    Related Questions in BOOTSTRAP-4

    • Displaying a Movie List on a Website Using Jinja2 and Bootstrap
    • I just cant make it work, HTML, JS and Firebase error
    • enable overflown data visible outside the container
    • Html + Css good response on computer (even in minimized mode) but bad on mobile
    • n is not a constructor error for bs4.5.2 dropdown and jquery 3.5.1
    • How to write HTML CSS code for a header navbar that too responsive
    • Change Opacity of Bootstrap Button
    • PhotoSwipe image position affected by other img elements in html on mobile
    • Should i learn Bootstrap in 2024
    • Having trouble sizing single resizable column with Bootstrap
    • In Boostrap 4 how can I change the the translucency of toasts to fully opaque?
    • Project was bootstrapped with an old unsupported version of tools while creating react app
    • Tooltip positioned too high with data-bs-placement="top" in Bootstrap 5
    • TypeError when using Popper with Bootstrap 4
    • How can I generate a Business Model Canvas with Bootstrap Cards and integrate it as html in a qmd-file?

    Related Questions in ANGULAR13

    • Angular external library is always initializing
    • Angular13- suddenly started to see "Uncaught TypeError: Illegal invocation"
    • Angular 13 - Getting error "Cannot read properties of null (reading 'getParsed')"
    • ng2-pdf-viewer problem with Angular >=12 version
    • scss shows maximum 2 buttons on the screen
    • I have two library / projects under one project and want to use project 1 standalone components into project 2
    • Angular - secondary router outlet stays in URL when navigating to new tab/window
    • Kendo-grid-checkbox-column generates duplicate empty columns in kendo-grid angular
    • How can we localise Angular 13 library?
    • How to remove multiple object from an array in angular 13
    • How to get multiple selected row index in the table in angular 13
    • How to get selected row index by checkbox in angular 13
    • Sticky footer doesn't work on angular application using a flex layout technique
    • Error: Module build failed | Angular13: ck-editor postcss-loader error
    • reduce same function call inside ngFor loop

    Popular Questions

    • How do I undo the most recent local commits in Git?
    • How can I remove a specific item from an array in JavaScript?
    • How do I delete a Git branch locally and remotely?
    • Find all files containing a specific text (string) on Linux?
    • How do I revert a Git repository to a previous commit?
    • How do I create an HTML button that acts like a link?
    • How do I check out a remote Git branch?
    • How do I force "git pull" to overwrite local files?
    • How do I list all files of a directory?
    • How to check whether a string contains a substring in JavaScript?
    • How do I redirect to another webpage?
    • How can I iterate over rows in a Pandas DataFrame?
    • How do I convert a String to an int in Java?
    • Does Python have a string 'contains' substring method?
    • How do I check if a string contains a specific word?

    Trending Questions

    • UIImageView Frame Doesn't Reflect Constraints
    • Is it possible to use adb commands to click on a view by finding its ID?
    • How to create a new web character symbol recognizable by html/javascript?
    • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
    • Heap Gives Page Fault
    • Connect ffmpeg to Visual Studio 2008
    • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
    • How to avoid default initialization of objects in std::vector?
    • second argument of the command line arguments in a format other than char** argv or char* argv[]
    • How to improve efficiency of algorithm which generates next lexicographic permutation?
    • Navigating to the another actvity app getting crash in android
    • How to read the particular message format in android and store in sqlite database?
    • Resetting inventory status after order is cancelled
    • Efficiently compute powers of X in SSE/AVX
    • Insert into an external database using ajax and php : POST 500 (Internal Server Error)
    • Privacy
    • Terms
    • Cookies
    • Homegardensmart
    • Math
    • Aftereffectstemplates