Create a unique HTML id dynamically using AngularJS

Hello, I am looking to create a unique identifier in html in the format 'a1', 'a2', etc. based on the values in the table. I am thinking of achieving this in the following way:

<div ng-controller="ddController" >
            <div class="containerslot" ng-controller="myCtrl">
                    <div ng-repeat="r in [1,2, 3, 4, 5, 6, 7, 8, 9, 10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]">
                        <span class="slot grey" id="{{'a'+r}}" ng-repeat="c in [1]" x-lvl-draggable='true' x-lvl-drop-target="true" x-on-drop="dropped(dragEl, dropEl)" ng-dblclick="showTabDialog(r)" data-color="grey"><button style="margin-right: 145px;
                            height: 22px;
                            display: block;" ng-click="openUserProfile(r)">config</button></span>
                    </div>
                </div>
            </div>

However, when my JavaScript retrieves the id, it only gets {{'a' + r}} instead of the actual identifier. For example:

var data = e.dataTransfer.getData("text"); // it collects {{'a'+r}} instead of 'a1'
                var dest = document.getElementById(id);
                var src = document.getElementById(data);

I am really struggling to find a solution for this. Any help would be appreciated.

Answer №1

If you want to achieve "String Interpolation in AngularJS" to transform your Ids into a1, a2, and so on, simply update id="{{'a'+r}}" to id="a{{r}}"

UPDATE: https://plnkr.co/edit/LOch8g8q6FtrMZPV?open=lib%2Fscript.js&deferRun=1 , it appears that the issue you are facing may be related to manipulating the DOM too early. Check the developer tools while running the code snippet to see if the a1 element is visible.

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

Troubleshooting iFrame Loading Issues with HTML5 PostMessage

Our code is utilizing the newest postMessage feature in HTML 5 to address cross-domain communication challenges. The issue I am facing is figuring out how to determine if the messages posted to an iFrame have been successfully loaded. If the frame fails to ...

Struggling to get this bootstrap carousel up and running

I can't seem to get this bootstrap carousel to switch slides, whether I use the indicators or arrows. My other carousel works perfectly fine and I've added all necessary Bootstrap and JavaScript CDNs. I'm puzzled as to why it's not func ...

Form validation displaying only the initial error message

When validating a form, I am encountering an issue where only the first error message can be displayed: ContactUs.prototype.desktopErrors = function(){ var THIS = this; THIS.$el.find('#submit').on('click', function(){ ...

Give the Row ID as a parameter to a personalized component within MUI Datagrid Pro

I am currently exploring the idea of incorporating an intermediate state to row checkboxes based on the selection status of other checkboxes within a detailed panel. My approach involves crafting a custom checkbox component and implementing some logical ...

Obtain the value of a JavaScript form with a dynamically generated field name

I am struggling with a simple javascript code and for some reason, it's not working. var number = 5; var netiteration = "net"+number; // now netiteration is equal to net5 var formvalue = document.forms.myformname.netiteration.value; Why is this co ...

When using the require() function in Node.js, the period "." is not being recognized as part of the command and

I recently encountered a problem while working on my project and reorganizing my files. I noticed that the "." in my requires are not being parsed correctly. Upon running my program, an error message is displayed: Error: Module './src/map/createMa ...

Updating the quantity of a Stripe subscription in Node.js: A Step-by-Step Guide

I'm having trouble modifying the quantity of items in an existing Stripe subscription. Whenever I attempt to update it, I encounter the following error: "error": { "message": "Invalid array", "param": &q ...

updating the count of items in a react virtual list

Popular libraries such as react-virtualized, react-window, and react-virtuoso all include an item count property similar to the one shown in the code snippet below from material-ui. However, this property is typically located within the return statement. ...

What could be the reason for Sequelize's findAll() method returning only a single object?

I am currently facing an issue where I can only retrieve one record out of many similar records when searching for products by brand and model name using Sequelize. This problem occurs even if there are multiple matching records, with the additional ones h ...

Troubleshooting: Style sheets not loading on a page rendered by node

Today was my first attempt at learning Node.js and creating a basic server to display a single page with a header tag. However, I encountered an error stating that the CSS file could not be loaded. This is the code I used: const express = require('ex ...

Please ensure that the minus sign is placed only at the beginning of the

My current regex is set up to only allow numbers and a comma in my numeric inputs. Now, I want to include the option of negative numbers as well. To accomplish this, I can modify the regex pattern like so: text.replace(/[^0-9,-]/g, '');. But the ...

Discovering specific keywords within HTML tags and performing replacements using jQuery

I am searching for specific strings within my HTML code, and if I find them, I want to replace them with nothing. For example: HTML: <img src=`javascript:alert("hello ,world!")`> My goal is to locate keywords like javascript, alert, etc, within H ...

Tips for implementing jQuery on a CSS selector's :before pseudo-element

My dilemma involves creating a div using CSS with an added X at the top-right corner using the before pseudo-class. How can I implement a function to close this div by clicking on the X with the assistance of javascript? https://i.sstatic.net/Z5uSq.png C ...

Error in React Typescript Order Form when recalculating on change

When creating an order form with React TypeScript, users can input the quantity, unit price, and select whether the item is taxable. In this simplified example, only 1 or 2 items can be added, but in the final version, users will be able to add 10-15 item ...

Insert a scrollbar into the new popup window on Internet Explorer after the window has been opened

I am looking to enable scrolling in a pop-up window after it has been opened. While FireFox offers the 'window.scrollbars' property for this, Internet Explorer does not have a similar feature. Is there a way to add scrolling functionality in IE u ...

The function nested within a constructor that includes `this.route` is not assigning it as an array

this.routeHandler = function () { let stations = ['KSFM', 'KPWM'] let coordinates = []; let allCoords = []; if (Array.isArray(stations) == true) { for (let i = 0; i < fetchRoute().length; i++) { fo ...

Connect controls to elements within a sibling component

My ImagesInput component utilizes an array called images to display the images. I have added a button for changing the images, but I am facing an issue in separating and changing the correct image. It seems to only modify the last index of each gallery a ...

Clicking while holding down the control key in Chrome causes the frame on my website to

My website consists of two frames - the main menu on the left and the content displayed on the right. However, I have noticed that when users use control+click in Chrome to open a new tab, the iframe page is displayed without the menu. Is there a way for ...

unable to submit form using angular and express

I am encountering an issue with a post request in AngularJS to express. The HTML form on the client side is defined as follows: <div ng-controller="LoginCtrl"> <form ng-submit="login()"> <div> <label>Username</lab ...

Extract the Top X elements from a multidimensional array

Consider an Array that consists of nested arrays: [ ["2000-01-01", "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d1a9a8abe091b6bcb0b8bdffb2bebc">[email protected]</a>", 1, 9, 338], ["2000-01-01", "<a href="/ ...