Is there a way to access the contents of ng-repeat using getElementById?

Is there a way to extract the data from ng-repeat?

<div ng-repeat="w in quick.wint">
   <div id="wname"><strong>{{w.Name}}</strong></div>
   <div id="wcount">{{w.Count}} Open Queues</div>
</div>

I am looking to store this information in a variable for printing purposes.

var wname = document.getElementById('wname').innerHTML;
var wcount = document.getElementById('wcount').innerHTML;
var popupWin =window.open('','_blank','width=300,height=300');
popupWin.document.open();
popupWin.document.write('<html><head><link rel="stylesheet" type="text/css" href="style.css" /></head><body onload="window.print()"><h1>Documentation</h1>' + wname + '</body></html>');
popupWin.document.close();

I would like to format the display on the printed document differently than how it appears in the browser. For instance, instead of:

<wname>
<wcount>

I want it to be shown as:

<wname> : <wcount>

Thank you in advance!

Answer №1

If you wish to differentiate each id, you can append the index as shown in the example below:

<div ng-repeat="w in quick.wint; let i = index">
   <div id="wname-{{i}}"><strong>{{w.Name}}</strong></div>
   <div id="wcount-{{i}}">{{w.Count}} Open Queues</div>
</div>

When accessing a specific row, simply concatenate the id like this:

var wname = document.getElementById('wname-1').innerHTML;
var wcount = document.getElementById('wcount-1').innerHTML;

Alternatively, if you need to retrieve all contents, consider using classes and querySelectorAll to obtain an array of children elements:

<div ng-repeat="w in quick.wint">
   <div class="wname"><strong>{{w.Name}}</strong></div>
   <div class="wcount">{{w.Count}} Open Queues</div>
</div>

const wnames = document.querySelectorAll(".wname")
const wcounts = document.querySelectorAll(".wcount")

Visit this link to learn more about querySelectorAll method.

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

Update ng-Bootstrap ToDate field by removing the date when selecting a fromDate

Is there a way to clear the date from the toDate input field while selecting a date from the fromDate input field in ng-bootstrap? <form class="row row-cols-sm-auto" *ngIf="showDateRangeImp"> <div class="col-12" ...

Generate a JavaScript variable in real-time and leverage it to retrieve the corresponding JSON response

After receiving a JSON response from an API as depicted in the image below: https://i.sstatic.net/5eq43.png I encountered an issue where the same column_code is used in both the variable_meta section and the data part of the response. This column code act ...

Triggering Jquery event multiple times

I am using a jQuery datatable that gets populated with data from a database through an AJAX call when a user clicks on a load button. The data is displayed based on the date selected by the user in a datepicker. I have also added an export button to allow ...

What is the standard character-encoding for HTTP header values when using AJAX?

Let's say I am utilizing AJAX to send a request to a server in this manner: $.ajax( { url: url, beforeSend: function (request) { request.setRequestHeader('X-Test', 'one'); }, }); The documentation for $.aj ...

How can I find the week of the month using Moment.js? (similar to Google Calendar)

Currently leveraging the fantastic features of Moment.js, I am facing a dilemma. How can I determine which week of the month a particular date falls into? The documentation for Moment js only seems to provide information on "week of year." For instance, if ...

Guide to converting a log string into JSON using Javascript

I encountered a console log that appears as follows: 2021-01-06T09:06:05.541212726Z D saveGarment: Function execution took 736 ms, finished with status code: 204 2021-01-06T09:06:10.844901031Z D saveGarment: Function execution started 2021-01-06T09:06:16.1 ...

Tips for adding elements to an angular $scope.array?

Currently, I am facing an issue that I cannot seem to pinpoint (most likely due to my limited expertise in AngularJS). In my HTML file, I have a basic ng-repeat set up like this: <ul> <li ng-repeat="fot in fotografia"><img src="{{fot.path ...

Form validation on the client side is not occurring, and the form elements cannot be edited

Having trouble with client-side form validation. Specifically, I need to ensure that passwords match in my registration form. Below is the JavaScript code snippet I'm using: $(document).ready(function(e) { $("#reg-form").submit(function(event) { ...

Is there a way to automatically refresh a page as soon as it is accessed?

My goal is to create a page refresh effect (similar to pressing Command+R on Mac OS) when navigating to a certain page. For instance: Currently, when I navigate from "abc.com/login" to "abc.com/dashboard" after successfully logging in, the transition occ ...

Using JavaScript to validate birth date selection along with three drop down menus in ASP.Net

Currently, I have implemented a functionality using three drop down controls to prompt users to select their birth date. In order to validate the selected date, I have incorporated JavaScript code in all three drop down "onChange" events. The function is ...

When I reload the page in Rails with AngularJS, the rendered content from AngularJS disappears

In my Rails application with Angularjs integration, I have a link labeled "Notes." When clicked, it directs me to the URL "http://localhost:3000/#/notes" and displays certain templates using Angularjs. However, when I reload the page, the templates disappe ...

What is the best way to keep classes added through jQuery even after retrieving all the data from the API?

I'm trying to maintain the "active" class in the nav-link when a tab is clicked, but the issue arises when fetching data from an API (using node) as it refreshes the page. Despite my research efforts, I have been unable to find a solution. Any assista ...

When working with AngularJS' ng-repeat in IE8, JQuery may encounter difficulties reading the innerHTML of a table row

I am attempting to implement a hover effect on table rows that changes the color when the mouse enters the row. I am utilizing JQuery and the on() method for this purpose, while the table is generated using AngularJS' ng-repeat. Everything works smoo ...

What could be causing the lack of value appearing after I clicked the button?

Setting the value for the array of images as an empty string does not return the expected result. When I move one of the 4 images and click the button, I anticipate a new array with the information of one of the four images including src, x, and y coordina ...

What is the best method for transforming a stream into a file with AngularJS?

Currently, I have a server returning a file stream (StreamingOutput). My goal is to convert this file stream into an actual file using AngularJS, javascript, JQuery, or any other relevant libraries. I am looking to display the file in a <div> or ano ...

Exploring the attrTween function in Angular with D3 insights

I'm currently trying to grasp the concept of utilizing the function attrTween in D3. My goal is to create a pie-chart using the example found at http://bl.ocks.org/mbostock/5100636. However, I've encountered some challenges when it comes to the ...

Iterating through data to showcase vertical columns for a specific time span of 3 years, highlighting only the months with available data

If data has been available for every month over the past 3 years, I need it to be displayed in a specific format. You can refer to this example fiddle for reference: https://jsfiddle.net/bthorn/ncqn0jwy/ However, there are times when certain months may no ...

Sending dynamic values to Cordova in an Onsen AngularJS application for the Share button

Working on developing an iOS Cordova application using Onsen UI and AngularJS. I have integrated a tool bar with a "share button" located on the right side. The page content is loaded dynamically, and my goal is to share specific text from the page. < ...

When utilizing the React API Fetch, there may be instances where not all data is returned. However

Having some trouble with my FetchData class. I am receiving a list of data, but it's in an array format. When I try to access specific values like countries: data.Countries[0], I can get individual values based on the index. However, what I really wan ...

To open a popup menu with a text box, simply click on the text box

Whenever the text box text is clicked, a popup menu should open with a text box. Similarly, when the filter icon in the right side corner is clicked, a menu should open with a list of checkboxes. However, currently both menus are opening when clicking on b ...