Utilizing AngularJs and Materialize.css to create numerous dropdown menus

I am encountering a troublesome issue that I just can't seem to resolve. My current setup involves using AngularJs to showcase a set of cards, each equipped with its own dropdown menu.

Here's the snippet of code in question:

<div ng-repeat="feedback in feedbacks"  
    class="card">
    <div class="cardMoreActionsButton">
        <a  class="dropdown-button" 
            dropdown 
            href="#"  
            data-activates="cardMoreActions{{feedback.FeedbackTrackerId}}">
            <i class="material-icons grey-icon">more_vert</i>
        </a>
        <ul id="cardMoreActions{{feedback.FeedbackTrackerId}}" 
            class="dropdown-content">
            <li>
                <a ng-click="archiveFeedback(feedback.FeedbackTrackerId)">
                     Archive feedback
                </a>
            </li>
        </ul>
    </div>
    Card content
</div>

Upon running this code, I encountered the following error:

Error: Syntax error, unrecognized expression: #cardMoreActions{{feedback.FeedbackTrackerId}}

This occurred at the following segment of code:

<a class="dropdown-button" dropdown="" href="#" data-activates="cardMoreActions{{feedback.FeedbackTrackerId}}">

What is the correct way to structure the expression to specify the activation of the corresponding ID? Additionally, how should I properly implement a materialize.css dropdown within an ng-repeat directive?

To provide more context, here is the activation code within the "dropdown" directive:

TK.directive('dropdown', function() {
    return {
        restrict: 'A',
        link: function(scope, elem, attr) {
            elem.dropdown();
        }, 
    }
});

Thank you in advance for any assistance!

EDIT

In my search for answers, I came across a related question:

Creating a custom materialize directive that works with an {{expression}} in data-activates attribute

Following the suggestions provided there, I attempted to add the ng-attr- prefix to both attributes ("id" and "data-activation"). However, this did not resolve the issue. Although it eliminated the error message, the dropdown menus remained hidden even though the "active" class was successfully applied to the dropdown button. Could this be linked to the fact that my directive is nested within an ngRepeat directive?

Any help or feedback would be greatly appreciated.

Below is the updated code after the edit, unfortunately still not yielding the desired outcome:

<div ng-repeat="feedback in feedbacks"  
    class="card">
    <div class="cardMoreActionsButton">
        <a  class="dropdown-button" 
            dropdown 
            href="#"  
            ng-attr-data-activates="cardMoreActions{{feedback.FeedbackTrackerId}}">
            <i class="material-icons grey-icon">more_vert</i>
        </a>
        <ul ng-attr-id="cardMoreActions{{feedback.FeedbackTrackerId}}" 
            class="dropdown-content">
            <li>
                <a ng-click="archiveFeedback(feedback.FeedbackTrackerId)">
                     Archive feedback
                </a>
            </li>
        </ul>
    </div>
    Card content
</div>

Answer №1

It seems that cardMoreActions is a function that needs to be updated to

cardMoreActions({{eedback.FeedbackTrackerId}})
.

I trust this information has been useful to you.

Answer №2

The issue is resolved with this solution

TK.directive('dropdown', function() {
    return {
        restrict: 'A',
        link: function(scope, element, attributes) {
            element.ready(function(){
                element.dropdown();
            });         
        }, 
    }
});

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

Improved Separation and Design in Node.js Application

I have developed a node application using express. I am trying to organize the different layers to enable unit testing of the application... However, I am facing an issue on how to call the router.js file that handles the post/get/delete methods in the ap ...

What is the correct way to establish and terminate a MongoDB connection in a Node.js application?

Hey everyone, I have a piece of code at this link (https://github.com/MrRav3n/Angular-Marketplace/blob/master/server.js) and I'm curious if I am properly starting and ending my database connection. Should I connect and end the db connection in every a ...

Tips for transferring a JavaScript variable to a servlet

I have implemented the selectable jquery plugin on my JSP page. I need to pass the selected string as a parameter to a servlet when the form is submitted. $(function() { $("#selectable").selectable({ stop: function() { var result = ...

Ways to retrieve a list of identifiers from arrays at both initial and subsequent levels

I'm currently dealing with a JSON/JavaScript structure that looks like this: { "comments": [ { "id": 1, "content": "lorem ipsum", "answers": [] }, { "id" ...

How to Use Laravel to Create HTML Divs Without Images

While working with a text editor, we have the ability to incorporate various HTML tags such as images and videos. However, I am only interested in displaying text fields. When I use {{$loop->content}}, it displays: <p><strong>EXAMPLE</st ...

Two components, one scroll bar, both moving within the same plane

For those interested, here is the JSFiddle link for further exploration: https://jsfiddle.net/q6q499ew/ Currently, there is a basic functionality in place where when you scroll past a certain point, an element becomes stuck until you start scrolling back ...

Styling with CSS: A guide to reducing paragraph margins within a div element

My current project involves using javascript to dynamically insert paragraphs inside a div element. Essentially, the script grabs the value entered into an input form when a button is clicked and adds it as a new paragraph within a specific div. However, I ...

Guarantee the successful execution of a server-side function using my client-side function

I am currently in the process of creating a website that utilizes Javascript and Asp.net. My code contains numerous functions on the client side, within my html code, while my server side functions are called using a webservice. How can I ensure that my c ...

What impact does adding 'ng' in unit tests have on how promises are handled?

Here is an example of a service that utilizes $q.when to wrap a promise from a third-party library: // myService.js angular.module('myApp', []) .service('myService', function($q, $window) { var api = new $window.MyAPI(); this ...

Creating an IntersectionObserver with the Composition API: A Step-by-Step Guide

I am currently in the process of incorporating an IntersectionOberver that will update the url once the viewport transitions into a new section. I came across This thread and now endeavoring to apply it in vue 3 compositon api. The script is being integra ...

Show or conceal a class

Hello there! I've been attempting to create a toggle effect using an anchor link with an "onclick" event to show and hide content. Despite my efforts with jQuery and JavaScript functions, I just can't seem to figure out the right approach. Here& ...

Generate a Vue component that automatically wraps text dynamically

Challenge I am looking for a way to dynamically wrap selected plain text in a Vue component using the mouseUp event. For instance: <div> Hello World! </div> => <div> <Greeting/> World! </div> Potential Solution Approach ...

Absolute positioning causes an element's height to increase

As I delve into the realm of typographical animations and seek to calculate the baseline of a font at various sizes, I've stumbled upon a peculiar discovery: It appears that the height values of elements tend to increase in an erratic manner when thei ...

Error: Unexpected token : encountered in jQuery ajax call

When creating a web page that requests remote data (json), using jQuery.ajax works well within the same domain. However, if the request is made from a different domain (e.g. localhost), browsers block it and display: No 'Access-Control-Allow-Or ...

MongooseError: The parameter `uri` passed to the `openUri()` function must be of type string, but instead received "undefined"

Recently delving into mongo, I encountered a connection error that has me stumped. The error message reads as follows: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose ...

Extracting specific key-value pairs from JSON data

Working with JSON data, I encountered a need to pass only specific key-value pairs as data to a component. Initially, I resorted to using the delete method to remove unwanted key-value pairs, which did the job but left me feeling unsatisfied. What I truly ...

css subcategories - divs failing to meet css criteria

I am encountering an issue where my subclass is not working on DIV elements. While the CSS rules are able to match inline tags like span and a, they do not seem to work with div. Please refer to the example provided below: <style> .row { disp ...

What effect does jQuery animation have on content compression?

Looking for guidance as I dive into jQuery and navigate the complexities... HTML: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <link rel="stylesheet" type="text/css" hre ...

Position the Bootstrap 5 navbar at the top of the page and set it

Is there a way to use the fixed-top class on a navbar without making it full width and overlapping the container? This is the code: <div class="container" style="border: 1px solid;"> <nav class="navbar fixed-top n ...

Difficulty with spacing in HTML/CSS styling

Here is what I'm currently working on: link to jsfiddle code * { margin: 0; padding: 0; } html { height: 100%; } header, nav, section, article, aside, footer { display: block; } body { font: 12px/18px Arial, Tahoma, Verdana, sans- ...