An example of a functional AngularJS menu with accordion-style dropdowns, dynamic data, and submenus created using list items (li) - see

My goal is to create a versatile accordion-style navigation menu with submenus in AngularJS. This menu should be able to dynamically load menu data, determine which items have submenus, and more. I have experimented with angular-ui/bootstrap accordion elements, but I prefer using list-items as they offer more flexibility in terms of styling.

The desired functionality includes:

  • Dynamic loading of menu data
  • Dynamic loading of submenu data
  • Dynamic assignment of which menus have submenus
  • Accordion-style behavior where clicking on one item with a submenu closes others
  • Clickable end-point menus that act as links or expand their submenus without navigating
  • Auto-collapse of submenus when clicking away from the menu area
  • Status awareness to highlight active menu items
  • Ability to indicate submenu presence and state through chevrons
  • Preferably implemented using CSS/HTML

For reference, I have a working jQuery version available here.

function initMenu() {
     // JavaScript function code here
}

// Other JavaScript functions...

$(document).ready(function () {
     initMenu();
 });

// Additional jQuery event listeners...

A sample JSON menu structure (in coffee-script) looks like this:

S.mainMenu = [
        // Menu items with icons and URLs
    ];

There are 3 regular menus and 2 menus with submenus in the JSON structure.

I am looking to transition this functionality from jQuery to Angular. I believe utilizing directives for both the top-level accordion menu and submenu would be an appropriate approach, but my directive implementation skills are still developing. Any guidance on converting this menu structure in Angular and determining the placement of trigger calls like $(document).ready would be greatly appreciated.

Creating a generic, dynamically loaded menu system with configurable numbers of menus and submenus could benefit many developers. The question has been structured to address various needs around implementing such a menu system efficiently.

Thank you for your assistance!

Answer №1

Check out this innovative angular directive that utilizes bootstrap's collapse plugin without the need for jQuery. It offers customization options to tailor it to your specific needs.

View Demo on Plunker

This accordion functionality is built on the template provided by Bootstrap:

<div id="parent">
    <div class="panel">
        <div data-toggle="collapse" data-parent="#parent" data-target="#child">test</div>
        <div id="child" class="collapse in">
            This is the content
        </div>
    </div>
    <div class="panel">
        <div data-toggle="collapse" data-parent="#parent" data-target="#child2">test</div>
        <div id="child2" class="collapse">
            This is the content
        </div>
    </div>
</div>

Answer №2

For those who are already utilizing Bootstrap for styling, I highly recommend integrating Angular-UI Bootstrap. This module eliminates the need to start from scratch. Check out this specific example, which is modeled after the Accordion demonstration in the documentation.

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

Capturing numerous data points with JavaScript

<span> <label class="label">Color</label> <span class="foo"><input name="Color" value="Blue" class="customs" maxlength="100" type="text"/></span> </span> </span> <span> <label cla ...

Alter the color of the dropdown background when it is changed

Currently, I am utilizing the Semantic UI React CSS library and find myself in need of changing the background color of dropdowns once an option is selected. https://i.sstatic.net/yZBK7.png to https://i.sstatic.net/LxTtT.png <Dropdown placeholder=&apo ...

Struggling to remove the translucent effect when hovering over the share button

I have been struggling with a seemingly simple issue for a few hours now. On my website, I have some share buttons located at . Although I want these buttons to remain completely black when hovered over, they are inexplicably becoming slightly transparen ...

Tips for adjusting the search bar's position on a mobile device when it is activated by the user

I need help with an open source project where I am developing a search engine using Angular. When using smaller screen sizes, the search bar is positioned in the middle but gets hidden behind the keyboard terminal when clicked on. Can anyone advise on ho ...

Unraveling the Mystery of Parsing a JavaScript Array

Here is what I have to work with: I have the city name, which is Littelside and it's stored in a variable called var city An array of {} objects, each containing address, city, name, state, and zip-code [{"address":"07288 Albertha Station",**"c ...

Error alert: $.simpleWeather function not found

Currently, I am attempting to incorporate simpleWeather.js from the website simpleweatherjs.com into my own website. However, upon inserting the html code onto my website, an error message pops up: Uncaught TypeError: $.simpleWeather is not a function ...

Efficient techniques for developing lazy-loading ajax services

What are some efficient ways to create lazy ajax services in angular-js? For instance, I need a resource that returns a promise such as: angular.module('MyModule',[]) .factory('myService', function() { return { getData: fun ...

Fresh class retains the characteristics of the former class

As I navigate my way through learning jQuery, I've encountered a puzzling issue that I can't seem to solve. No existing articles seem to address my specific problem, so I am turning to this platform in hopes of finding a solution. I'm puzz ...

What is preventing me from modifying the styling of select options in Internet Explorer 8?

I am trying to change the font style in a select-option box. After testing in IE6, Chrome, and Safari, it is working fine! However, I encountered an issue with IE8 where the font style was not changing. The following code did not work: <select name= ...

In the HTML code, the select option will show the value with an empty colored div and then

Is it possible to create an HTML select option that displays a value along with an empty color div? Can this be achieved using HTML, JavaScript, or jQuery? I have attached a png file for reference, and I want the output to look similar. <select> ...

Using .get methods with jQuery's .on

I need to retrieve the tag name of the element that is clicked inside an li when the user interacts with it. The li element gets dynamically added to the HTML code. I have implemented the following code, but unfortunately, it does not seem to be functionin ...

Unleashing the power of ::ng-deep to access CSS in an Angular child component

I'm attempting to modify the CSS class of a child component by using ::ng-deep. Despite my efforts with various iterations of the code provided below, I have been unsuccessful in accessing the CSS. The structure of the HTML component is depicted in th ...

Clicking the set button in Jquery mobile datebox resets the time

I am experimenting with the jquery mobile datebox (courtesy of Jtsage) to select time and date. Unfortunately, every time I reset the time by clicking the set button, I am unable to retrieve the correct time. Below are my code snippets: $.extend($.jtsag ...

"Using jQuery to store items in local storage that persist even after refreshing the

Here is the code snippet I have: <input type="text" id="player"/> <button>join</button> <div id="tournament"></div> Here is the jQuery function: $(document).ready(function(){ $('button').click(function(){ ...

What is the best way to activate a JQ function with my submit button?

Is there a way to trigger a JQ function when clicking the submit button in a form? I managed to make Dreamweaver initiate an entire JS file, but not a particular function. ...

Encountering an error while running `npm start` in Angular

Attempting to utilize AngularJS with live preview using the following command: npm start Current npm version: 4.3.0 Encountering the following errors: Microsoft Windows [Version 10.0.14393] (c) 2016 Microsoft Corporation. All rights reserved. C:&b ...

Activate the radio button with jQuery when the event occurs

I have been experimenting with using HTML and JS along with the functionality provided by bootstrap-switch.org to toggle between two groups of radio buttons within a form. However, I am encountering difficulty in setting the first radio button in the secon ...

Rotating through 3 divs with a FadeIn/Out effect

Hey, I created this code snippet to change the opacity of three different divs. The intention is for every 10 seconds to display #background2, hide #background1, and then hide #background2 while showing background 3. <div id="background1" class="bac ...

The sequence of code execution is incorrect

Although I am aware of Javascript's asynchronous nature, I'm perplexed as to why this particular scenario is unfolding the way it is. At line 27 below, I invoke the 'GetProducer' function which is meant to fetch data for a specific pro ...

How to utilize a parameter value as the name of an array in Jquery

I am encountering an issue with the following lines of code: $(document).ready(function () { getJsonDataToSelect("ajax/json/assi.hotel.json", '#assi_hotel', 'hotelName'); }); function getJsonDataToSelect(url, id, key){ ...