The submenu in Angular Bootstrap 3 navbar fails to trigger

I am currently using Angular 1.2.1 and Bootstrap 3.0.2.

When I try to generate a menu using ng-repeat in my plain vanilla nav menu with a drop down, the submenu does not function as expected.

Here is the HTML code:

            <ul class="nav navbar-nav" ng-repeat="data in main_menu">
                <li ng-class="{'dropdown' : data.nodes}">
                  <a href="{{data.link}}" ng-class="{'dropdown-toggle' : data.nodes}">{{data.name}} <b class="caret" ng-if="data.nodes"></b>
                  <ul ng-if="data.nodes" ng-repeat="items in data.nodes" class="dropdown-menu">
                      <li><a href="{{items.link}}">{{items.name}}</a></li>
                  </ul>
                </li>
            </ul>

In the Controller:

$scope.main_menu = [
  {
    name: 'Home',
    class: '',
    link: '/',
    nodes: false
  },
  {
    name: "DropDown",
    class: 'dropdown-toggle',
    link: '#',
    nodes: [
      {
        name: "Node2",
        class: '',
        link: 'link'
      },
      {
        name: "Node2",
        class: '',
        link: 'link'
      },
      {
         name: "Node2",
         class: '',
         link: 'link'
      },
      {
         name: "Node2",
         class: '',
         link: 'link'
      }
    ]
  }

 ];

The normal bootstrap html submenu function works fine. Any suggestions on how to fix this issue?

After checking further...

The original Angular html Block has some incorrect syntax. With the adjustments made below, it now renders the correct html - however, the dropdown still does not work correctly.

            <ul class="nav navbar-nav" >
                <li ng-repeat="data in main_menu" ng-class="{'dropdown' : data.nodes}">
                  <a href="{{data.link}}" ng-class="{'dropdown-toggle' : data.nodes}">{{data.name}} <b class="caret" ng-if="data.nodes"></b></a>
                  <ul ng-if="data.nodes"  class="dropdown-menu">
                      <li ng-repeat="items in data.nodes"><a href="{{items.link}}">{{items.name}}</a></li>
                  </ul>
                </li>
            </ul>

Answer №1

Here are two simple steps to follow:

  1. Firstly, include the attribute data-toggle="dropdown" for the link.

  2. Secondly, make sure to update the controller by replacing link: '#' with link: ''.

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

Using JavaScript, capture and rearrange the colors of the store's section. JS

I'm facing a challenge with creating dynamically colored divs based on different sections in the background. While I can achieve this using CSS, I wonder if there's a more efficient way to handle the colors with JavaScript. In my current setup, ...

Serve Webpack bundle on various routes - Express Way

I recently completed a web application using an Express backend and React frontend. Upon sending a request to the Express server, it undergoes a process where the URL is checked against the backend routes. If there isn't a match, the React bundle gen ...

I am looking for a way to locate all meta tags that begin with either "ABC_" or "XYZ_" by using jQuery

I am facing a challenge with multiple <meta> html tags. My task is to utilize jQuery to retrieve all the meta tags where the name begins with "ABC_" or "XYZ_", and then iterate through them. This is what I have accomplished so far: var tags = $( "m ...

How can a personalized greeting be added in Node.js to welcome a user by their first name retrieved from a MongoDB database upon logging in?

I am looking to create a login and signup form using React that will allow users to input their name, email, and password. After submission, I want the next page to be a personalized congratulations page with the user's name dynamically inserted. Can ...

Looking to develop a dynamic password verification form control?

I am in the process of developing a material password confirmation component that can be seamlessly integrated with Angular Reactive Forms. This will allow the same component to be utilized in both Registration and Password Reset forms. If you would like ...

Implementing custom validation in React to dynamically enable/disable buttons

I am working on a basic form that includes 3 input fields and one submit button. The submit button is initially disabled, and each input field has its own custom validation logic using regex. I am looking for a way to enable the button only when all the ...

Find the item in the pop-up window

When removing a user from my list, a JavaScript popup pops up prompting to confirm the action with two buttons "OK" / "Annuler" : https://i.sstatic.net/BEdH2.png Is there a way to use Selenium to find and interact with these buttons? ...

Utilizing vanilla JavaScript within a React.js component: A step-by-step guide

I have implemented chartist.js in my React component, and I am facing an issue with displaying the chart on the web page. I am following the example provided at Below is the code snippet: var Chartist = { version:'0.9.5' } (function (wind ...

Adding a badge to a div in Angular 6: What you need to know!

How can I add a badge to a specific div in Angular 6? I have dynamic div elements in my HTML. I want to increase the counter for a specific div only, rather than increasing it for all divs at once. For example, I have five divs with IDs div1, div2, div3, ...

The command "json_encode($array)" does not seem to be encoding the complete array

I ran a test on the following: <? echo json_encode($array) ?> result: ["PG","Kevin Sad","8000","12"] Upon placing it within a form option value to be selected by my script function: <option value=<? echo json_encode($array) ?> > op ...

Angular - ui-router states are not being detected

I'm currently working on a Spring and Angular JS web application project. The structure of the project is as follows:https://i.sstatic.net/xgB4o.png app.state.js (function() { 'use strict'; angular .module('ftnApp') .con ...

Enhance user experience with a dynamic Bootstrap combo box that updates based on

I am currently facing an issue with the bootstrap combobox plugin. I am having trouble changing the selection and sending that information from the view to the controller. $('#MyCombo').on('change', function () { var data = $(this) ...

Adjust the scroll position in HTML by using a fixed navbar with Bootstrap 4

I am currently working on a single-page website with multiple sections. Users can navigate to these sections either by scrolling or by clicking on the navbar links. The issue I am facing is that the Bootstrap 4 navbar is fixed to the top, causing the conte ...

Updating state from multiple handlers using the useReducer hooks in React: a complete guide

Currently, I am utilizing { useReducer } to handle the state of my form. Nonetheless, I have two distinct handlers: handleChange() = used for input changes (this one is functioning as intended) const handleChange = async (e) => { dispatch({fiel ...

Switch out the icons within a return statement in JavaScript

Help! I have 5 empty star icons (<StarBorderIcon/>) displayed for a product on the material-ui website. I need to replace them with filled star icons (<StarIcon/>) based on the rating entered into a function. I attempted to use replace(), but i ...

What is the NodeJs Event loop and how does it work with libuv and V8

NodeJs is made up of the V8 engine and the libuv library. The V8 engine has its own event loop with a call stack, event queue, and micro task queue to run our main code. The libuv also has an event loop with phases like times, callbacks, poll, check, and ...

Guide to effectively utilizing jQuery Deferred within a loop

I have been working on a function that needs to loop through a dataset, updating values as it goes along using data from an asynchronous function. It is crucial for me to know when this function finishes running the loop and completes all updates. Here is ...

The addEventListener feature in Bootstrap 5.2.3 seems to be malfunctioning

I have a sample page with a Bootstrap dialog being returned from the server. I want to display it inside a DIV. However, when clicked, I receive this error: Uncaught TypeError: myModal.addEventListener is not a function It points to this line of code: ...

Maximizing JavaScript efficiency: Returning a value within an if statement in an AJAX call

In my function, I have a condition that checks the idType. If it is 1, an ajax call is made to a php file to retrieve the name associated with the specific idName and return it. Otherwise, another example value is returned. function obtainName(idName, idTy ...

"Implementing constraints in Postgres using Node.js

Currently, I am struggling with writing a constraint code to handle situations where a user tries to search for an id that does not exist in the database (specifically PostgreSQL). Despite my efforts, the if statement in the code below does not seem to be ...