Using .after() in AngularJS for nested ng-repeat recursive iteration

I have a straightforward layout

 function adjustLinks($scope) {
    $scope.links = [
        {
            text: 'Menu Item 1',
            url: '#',
        },{
            text: 'Menu Item 2',
            url: '#',
            submenu: [
                {
                    text: 'Sub-menu Item 3',
                    url: '#',
                },{
                    text: 'Sub-menu Item 4',
                    url: '#',
                    submenu: [
                        {
                            text: 'Sub-sub-menu Item 5',
                            url: '#',
                        },{
                            text: 'Sub-sub-menu Item 6',
                            url: '#',
                        }
                    ]
                }
            ]
        },{
            text: 'Menu Item 3',
            url: '#',
        }
    ];
}

I am interested in creating a table where the child items are displayed in successive rows following their parent item:

Menu Item 1

Menu Item 2

Sub-menu Item 3

Sub-menu Item 4

Sub-menu Item 5

Sub-menu Item 6

Menu Item 3

<table>
<thead>
  <tr>
     <th>Title</th>
     <th>Url</th>
  </tr>
 </thead>
 <tbody>
  <tr>
     <td>Menu Item 1</td>
     <td>#</td>
  </tr>
  <tr>
     <td>Menu Item 2</td>
     <td>#</td>
  </tr>
  <tr>
     <td>Sub-menu Item 3</td>
     <td>#</td>
  </tr>
  <tr>
     <td>Sub-menu Item 4</td>
     <td>#</td>
  </tr>
  <tr>
     <td>Sub-menu Item 5</td>
     <td>#</td>
  </tr>
  <tr>
     <td>Sub-menu Item 6</td>
     <td>#</td>
  </tr>
  <tr>
     <td>Menu Item 3</td>
     <td>#</td>
  </tr>
 </tbody>
</table>

I have explored using ng-repeat-start and ng-repeat-end, but it does not meet my specific requirements.

Would appreciate any suggestions or guidance on how to achieve this setup. Thank you!

Answer โ„–1

In case you are utilizing this code for website navigation, consider placing it within a nested <ul> and applying stylish CSS to enhance its appearance. Here is an example:

<ul ng-repeat="item in menuItems">
  <li>{{item.name}}</li>
  <ul ng-repeat="subItem in item.submenu">
    <li>{{subItem.name}}</li>
  </ul>
</ul>

This structure can be used to create a well-organized navigation menu on your website.

Answer โ„–2

Here are some valuable resources to check out:

https://www.freecodecamp.org/news/tag/angular/

The examples provided in the first link might be exactly what you're looking for.

This question has definitely been asked before, so a quick search online should yield even more examples and helpful information related to your query.

Answer โ„–3

Currently, my approach is not flawless. Rather than a conventional table structure, the resulting HTML comprises nested ul/li elements that are styled with CSS to mimic the specified design.

The main issue stems from complications in placing tbody and tr within a directive. If anyone knows of a workaround for this, I would greatly appreciate your insights.

The basic markup looks like this:

<menucollection menucollection='links'></menucollection>

Backed by 2 directives:

window.app.directive('menucollection', function () {
    return {
        restrict: "E",
        replace: true,
        scope: {
            menucollection: '='
        },
        template: "<ul><menuitem ng-repeat='menuitem in menucollection' menuitem='menuitem'></menu></ul>"
    }
});

window.app.directive('menuitem', function ($compile{
    return {
        restrict: "E",
        replace: true,
        scope: {
            menuitem: '='
        },
        template: "<li>{{menuitem.Name}}</li>",
        link: function (scope, element, attrs) {
            scope.catMarker = attrs.marker;
            scope.subcatMarker = attrs.marker + ' ยป  ';

            if (scope.menu.Children.length > 0) {
                element.append('<menucollection menucollection="menu.submenu"></menucollection>');
                $compile(element.contents())(scope);
            }
        }
    };
});

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

A guide on how to implement the closing functionality of a CSS menu when clicking outside the menu using

I have a drop-down navigation menu implemented on a website using CSS. The sub-menus appear when hovering over specific items. While this functionality works well on desktop, I am encountering an issue on touchscreens. When clicking outside the menu area, ...

Tips and tricks for implementing vuetify tooltips within a list component

Looking for help with my code: <div id='app'> <v-app> <v-list-tile-content> <v-list-tile v-for="(item, index) in items" :key="item.id" > <v-list-tile-action> {{index+1}}. </v-list-tile-action> < ...

How can I toggle input disablement in Bootstrap depending on switch selection?

I have been exploring the Bootstrap 5 documentation in search of a way to disable other input fields when a toggle switch input is set to 'off'. The parent element for this scenario is #member_form, and the switch itself is identified as 'to ...

Save information in a session using html and javascript

I'm having trouble accessing a session variable in my javascript code. I attempted to retrieve it directly but ran into issues. As an alternative, I tried storing the value in a hidden HTML input element, but I am unsure of how to properly do that wit ...

Step-by-step guide on uploading a multipart file with AngularJS and Spring MVC

Currently, I am attempting to utilize AngularJS and Spring MVC for file uploading. In my application-context.xml file, I have configured a multipartResolver bean as follows: <mvc:annotation-driven /> <bean id="multipartResolver" ...

Is it possible to bundle *.html templates using Require.js Optimizer functionality?

What is the best approach for packaging HTML templates (also known as 'partials') in an Angular.js app when it's concatenated and minified for distribution? Should they be included in the single file, or zipped along with other directories s ...

Guidelines on launching an ionic 4 modal using routes

How can I open a modal using routes? I attempted the following approach, but it did not work as expected: ngOnInit() { this.launchModal(); } async launchModal() { const modal = await this.modalController.create({ component: AuthPasswordR ...

The vast expanse of the cosmos, replacing the

When attempting to simulate pressing the ENTER key in my code, I am getting the same result as if I pressed SPACE instead. I'm not sure why this is happening. field.clear().click().sendKeys("Hello"); browser.actions().sendKeys(protractor.Key.ENTER).p ...

Is there a hierarchy to be followed within the <head> element?

I have been developing websites using HTML for nearly 3 years now, but since I had to teach myself, there are still a few things I am unsure about. One question that has recently become important is whether it is possible to create groups within the <h ...

The connection timed out when attempting to send a POST request from the client side to the API

After setting up a basic https response to send JSON data from the client to an API endpoint named /api on my a2 web server, I encountered an issue where the connection was being refused and no logs were appearing in the terminal accessed through SSH. The ...

Different Zoom feature for JIT Graph

I'm currently working with the Java Infovis Toolkit and I'd like to use buttons for zooming in and out instead of using the mouse wheel. Can someone guide me on how I can implement two separate buttons for Zoom In and Zoom Out functions? ...

"What is the best way to change the props of a React component that has already been rendered from App.js

My React component, MoviesGallery.js, is set up with the following structure: class MoviesGallery extends Component { constructor(props) { super(props) this.state = { currentImage: 0 }; this.closeLightbox = this.closeLightbox. ...

Positioning the comments box on Facebook platform allows users to

Need assistance, I recently integrated the Facebook comments box into my Arabic website, but I am facing an issue where the position of the box keeps moving to the left. Here is an example of my website: Could someone please suggest a solution to fix the ...

open a new window with a reference based on the name

In order to obtain a reference to the currently open window, I utilize the following code: var refWindow = window.open("mypage1", "name_mypage"); If I wish to close the window, I simply use this command: refWindow.close(); When I refresh the screen (by ...

Changing the order of element names depending on their location within the parent element using jQuery

<div class="content"> <div> <input type="text" name="newname[name]0"/> <div> <input type="text" name="newname[utility]0"/> <div> <textarea name="newname[text]0 ...

What steps can I take to ensure that my popup images continue to appear?

Currently, I am working on creating a webpage that features thumbnails sourced from a local geoserver. The goal is to have these thumbnails expand into dialog windows that can be moved around. While I have successfully implemented the functionality to expa ...

Ways to extract particular items from a JSON array and store them in a JavaScript array

I am dealing with an external JSON-file structured as follows: { "type":"FeatureCollection", "totalFeatures":1, "features": [{ "type":"Feature", "id":"asdf", "geometry":null, "properties": { "PARAM1":"19 16 11", ...

The image in drag and drop ghost preview is not appearing on Firefox

I want to show a ghost element instead of the default browser preview while dragging and dropping. However, in Firefox, the image inside the ghost element is not displayed during dragging. Oddly enough, if I drop it and then drag again, the image does appe ...

Altering webpage content through the use of Ajax

I need a solution for dynamically updating web page content using JavaScript AJAX. One idea I had was to store different div layouts in separate files, like so: BasicDiv.div: <div> <p>Some Text</p> <button> A Button </ ...

error message: The file you are trying to access does not exist due to the

I seem to be facing an issue with my package.json file. I am trying to include a new "command" in a correctly written package. Specifically, I am looking to add a command that will load test data, so I updated the scripts section as follows: "load-test-da ...