How do I retrieve a template variable or reference from typescript in Angular?

Within my Angular project, I am attempting to retrieve the value from

<td [innerHTML]='rupee.replaceHTML' #term></td>
and assign it to the variable newdata.

Exploring further into the functionality, there are 2 buttons named change and concourse. Upon clicking the concourse button, the value within the HTML below will be altered. My goal is to capture this updated value in the variable newdata using localStorage for future access.

How can I go about retrieving the HTML value and storing it in new_data?

.html file

<mat-list-item>New Life</mat-list-item>
 <mat-list class="textFields">
   <table>
     <tr>
       <td [innerHTML]='rupee.replaceHTML' #term></td> ---> Access the value here
      </tr>
     </table>                
 </mat-list>

//button
<button mat-raised-button type='button' (click)='concourse(kada, term)'>Confirm

            

component.ts

export class Pinky { 
  @ViewChild('term') editElem!: ElementRef<HTMLTableDataCellElement>;
    

//button function       
concourse(rec: FillData, nada: HTMLTableDataCellElement) {
  const { a,b,c,d } = rec;
  let maan= nada.innerText;
  localStorage.setItem('FillData', JSON.stringify(rec));

   var new_data = JSON.parse(localStorage.getItem('FillData') || '{}') as FillData

-------------------//Can I access #term value here?-------------------------

    new_data.{{?}}= maan;                 ----------> Assign the value here ?
    localStorage.setItem('FillData', JSON.stringify(new_data));
}

Interface

export interface DraneMan {
  maan:string;
}

Answer №1

With a @ViewChild('term') already set up, you can easily retrieve it using this.editElem.innerHTML.

In addition, there is a binding [innerHTML]='rupee.replaceHTML'. Instead of reading directly from the DOM, consider using ruppee.replaceHTML as the primary source of truth for your data.

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

Modify the file format depending on the browser being used as Internet Explorer

Currently seeking the most effective method to dynamically alter the file extension of certain images (from .svg to .png) specifically for Internet Explorer users. Uncertain about the optimal approach: consider parsing the HTML code with PHP utilize jQu ...

Comparing time in string format using a MongoDB aggregate query

My database has the following data stored: collection name: movies: [ {id:1, name:"abch", start:"12:00 pm", end:"03:00 pm"}, {id:2, name:"Annabelle", start:"08:30 am", end:"10:00 am"}, {id:3, name:"Spider Man homecoming", start:"11:30 am", end:"03:0 ...

Storing JSON data retrieved from an API into a class property using the fetch function: a step-by-step guide

I am faced with the challenge of communicating with a localhost API that I have created in my React application class. This API is responsible for returning a list of JSON data, and my goal is to store this data in a property. Having limited knowledge abo ...

Is there a way to retrieve the $state object from ui router in the console?

I attempted to modify the route from the console by using this method to access the $state object: $inject = angular.injector(['ng', 'ui.router']); $inject.get('$state').go Unfortunately, I encountered an error: Uncaught Er ...

Choose only the options that are present in both arrays

I am working on creating a multiple select feature that displays all nodes, but only checks the ones that are present in 2 arrays. My front end is developed using Angular 8 and TypeScript. private mountSelect(nodesInRelation, lineApiKey) { console.lo ...

Tips for obtaining intellisense for the value in a readonly string array property within an object without relying on generics

Keeping it brief and to the point. What is the reason behind this? type ReadonlyStringArray = readonly string[] type TEnumGeneric<EnumIsh extends ReadonlyStringArray> = { type: "enum", values: EnumIsh } type TEnumImplied = { t ...

Problem with ng-repeat and custom directive in the header row

I'm currently in the process of transitioning our thead generation to a directive. However, I've noticed that when using this directive, the headers lose their styling and become clustered on the left side. Can anyone provide some assistance on w ...

Directive not working on Mozilla Firefox

Currently, I have a directive set up to display an image as a background image. This works perfectly fine in Chrome and Safari, but for some reason, it doesn't seem to be functioning properly in Firefox as the background images are not showing up. Aft ...

Challenges encountered while working with OpenWeather API

I created a weather prediction web application using p5.js. It functions perfectly on my local server. However, I keep encountering this issue on the GitHub page: Mixed Content: The page at '' was loaded over HTTPS, but requested an insecure ...

Calling an ajax request to view a JSON pyramid structure

My experience with ajax is limited, so I would appreciate detailed answers. I have a Pyramid application where I need to load information via ajax instead of pre-loading it due to feasibility issues. I want to retrieve the necessary information through a ...

I am looking to create an engaging photo viewing experience by utilizing a modal to display each image in my gallery when clicked

I created a stunning image gallery featuring 13 photos that I discovered on W3Schools and customized to suit my own preferences. The gallery looks great, but there's an issue - only the first image can be opened using a modal window. I tried editing s ...

Is there a way to prevent certain folders that have .vue files from being included in the VueJS build process?

https://i.sstatic.net/YU1rB.png module.exports = { presets: [ '@vue/app' ], module:{ rules: [ { test: /\.vue$/, exclude: [ './src/components/Homepages/number1', './src ...

The jquery script for the dynamic remove button is malfunctioning

I have successfully implemented code to display dynamic controls using jQuery. Below is the working code: <script type="text/javascript"> $(document).ready(function() { $("input[value='Add']").click(function(e){ e. ...

Finding the correct column in a drop-down menu based on a table array using AngularJS

In my controller, I have data like this: $scope.operationData = [ { "label" : "Inventory", "labelType" : "Master Tables", "type" : "PROCESSOR", "outputStreams" : 1, "elementType" : "TABLE", "name" : ...

What is the best way to retrieve information from a local JSON file and store it in the state of

I am currently working on a project to develop a movies/series search app using Next.js and React based class components. I have successfully imported JSON content and displayed it using the map function as shown below: <div> {Appletv.shows.map(( ...

Utilize API with unique characters in the URL

Attempting to make an API call from the front end using this API: http://localhost/search?userName=... get(endpoint: string, responseType = 'json', params: HttpParams = null): Observable<any> { let url = this.getHost() + endpoint; i ...

Using Typescript and react-redux with a Stateful Component: The parameter type 'typeof MyClass' does not match the expected component type

I've been trying to dive into the world of Typescript, React, and Redux. However, I've hit a roadblock at the moment. This is the error I encountered: ./src/containers/Hello.tsx [tsl] ERROR in /home/marc/Development/TypeScript-React-Starte ...

How to modify ID data with AngularJS ng-repeat

I am currently searching for a solution to easily modify an ID within a repeated ng-structure. This scenario involves having a customer table with unique customer IDs, which are then utilized in another table related to orders. When I retrieve data from th ...

Can you explain the significance of Pageset to me?

I've been searching online but haven't found a definitive answer yet. Can someone explain the concept of Pageset to me? When someone mentions including code in Pageset, what exactly are they talking about? ...

Unable to integrate npm package into Nuxt.js, encountering issues with [vue-star-rating] plugin

Just starting with nuxt js and running into issues when trying to add npm packages. Below are my attempts. star-raing.js import Vue from 'vue' import StarsRatings from 'vue-star-rating' Vue.use(StarsRatings) nuxt.config.js plugi ...