Dynamically attach rows to a table in Angular by triggering a TypeScript method with a button click

I need help creating a button that will add rows to a table dynamically when pressed. However, I am encountering an error when trying to call the function in TypeScript (save_row()).

How can I successfully call the function in TypeScript and dynamically append rows by clicking on the button?

HTML:

<table id="myTable">
<thead>
<tr>
   <th>GEOGRAPHY</th>
   <th>COUNTRY</th>
   <th>STATE</th>
   <th>REGULATION</th>
   <th>SMS</th>
   <th>WEB</th>
   <th>EMAIL</th>
   <th>OPERATION</th>
</tr>
</thead>
   <tbody #ir>
   </tbody>
</table>    

TypeScript:

var d=geo_Value;
var len=d.length;       
var  row = this.renderer.createElement('tr'); 
const col=this.renderer.createElement('td');
row.appendChild(col);  

col.outerHTML ="<tr id='row"+len+"'><td 
id='name_row"+geo_Value+"'>"+cou_Value+"</td><input type='button' 
id='save_button' value='Save' class='save' onclick='save_row("+len+")'> 
</td></tr>";

this.renderer.appendChild(this.ir.nativeElement,row);
let idGet=document.querySelectorAll('#save_button');
var myMessage = "it's working";

function save_row(a) {
}

Answer №1

When working with Angular, it is important to ensure proper event binding like so:

id='save_button' value='Save' class='save' (onclick)='save_row("+len+")'> 

It appears that brackets are missing in your code.

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

How can I use "Lite-Server" with NPM start to showcase my index.cshtml file on the browser?

Currently, I am trying to navigate the world of Visual Studio Code and figure out how to run/compile my project. Starting a new project in Visual Studio was simple enough, but now that I'm working with Visual Studio Code, I find myself struggling to s ...

The custom declaration file for the 'react-dates' module could not be located

I've been struggling to create a custom declaration file for the 'react-dates' npm package, but I'm facing issues with the compiler not recognizing my declaration file. Whenever I try to import DateRangePicker from 'react-dates&ap ...

Tips for specifying the "url" parameter in xmlhttp.open() for utilizing Ajax in communication with node.js

server.js has the ability to generate a random number. I am trying to retrieve a random number from the server and utilize xmlhttp to send a request. However, the string value remains unchanged when I visit http://localhost:3000/index.html. What could be c ...

Unveiling the essence of Lodash's differenceBy functionality

I am facing a challenge with two arrays of objects. I need to identify the differences between the newData and oldData arrays based on their identifiers. Specifically, I want to display objects from oldData whose identifiers are not present in newData. Her ...

Is there a way to pass a form error to the parent component as a parameter in React?

I am just starting to learn React. I have created a form and I want to inform the parent component about any input errors that occur. I attempted to use the variable myError as a prop similar to how I used the next method, but unfortunately, it did not wor ...

The initial Ajax request returned an empty data string, but upon retrying, the correct data

Let's address the current situation Previously, I had a free domain that was unexpectedly closed by the web admins without any explanation. Everything functioned perfectly on that domain, but after opening a new one on a different site, I started enc ...

Is there a way to refresh a Material-UI data table in React whenever a user takes any action?

I am facing an issue with my Lock-Unlock button and delete button. The problem arises when I render data from axios using the useEffect hook, it works fine. However, if I try to lock or unlock a user, the table does not update automatically. This indicates ...

Send a variable from a next.js middleware to an API request

I've been attempting to pass a middleware variable to my API pages via "req" but have encountered some issues Even after trying to send the user token to pages using "req", it consistently returns null The middleware file in question is: pages/api/u ...

React validation functionalities

Incorporating React, I am attempting to implement a validation feature within a footer containing multiple buttons with unique values such as home, orders, payments and more. My goal is to dynamically display an active state for the button corresponding to ...

Running your Angular application on a Node server: Step-by-step guide

I am looking to deploy my application using express on a Node server. This is the content of my server.js file: var express = require('express'); var path = require('path'); var app = express(); app.get('/', (req, res) => ...

The useEffect hook is causing a loop of API calls after successfully fetching data

I've been working on fetching data from my API and then performing some mappings to present it in the desired format. The challenge I'm facing is that the API calls are asynchronous, so I need to wait for the response before updating my dataset. ...

Is there a way to ensure my chat view functions properly without relying on partial views?

I am currently working on integrating a private chat feature using SignalR in my project, and I have encountered an issue while creating a View with accessible model values to pass to the server. Specifically, I have a list of doctors, and when a user clic ...

Guide to implementing a DataTable in MVC4 UI using jQuery

Looking to set up a DataTable using jQuery similar to the one shown in this image: https://i.stack.imgur.com/DNUcd.png I'm not very comfortable with jQuery, so please be patient and avoid asking me what I've tried. I don't know how to stru ...

The values of nested objects are not being passed as parameters from the AJAX call to the action method

How can I ensure that the nested object values in the parameter are passed correctly to the action method in the controller along with the full object? When calling the AJAX method, the values in the object inside the red ring on the pictures do not get p ...

What is the best way to implement rate limiting for asynchronous API calls within a specific timeframe?

I have a project that requires me to make over 500 calls simultaneously from my NodeJS server to a third-party server. The issue is that the third-party server has a restriction of only allowing a maximum of 50 calls per second. Can someone assist me in im ...

Stopping the execution of jQuery().load()

The .load() feature in the jQuery library allows users to selectively load elements from another page, based on specific criteria. I am curious to know if it's feasible to stop or cancel the loading process once initiated. In our program, users can e ...

A JavaScript code snippet to format a phone number in the pattern xx-xxxxxx

Please help me create a JavaScript function that can determine if the text in a textbox is a number. If it's not a number, I would like the function to focus on the textbox and change the format to look like this (xx-xxxxxx) when numbers are typed in, ...

Define unique positions for multiple shapes and then combine these shapes

import * as THREE from 'three'; import * as BufferGeometryUtils from 'three/addons/utils/BufferGeometryUtils.js'; const renderer = new THREE.WebGLRenderer(); renderer.setSize( window.innerWidth, window.innerHeight ); document.body.appe ...

Issue with autoplay slideshow functionality not activating when opened in a new tab

The owl.carousel.js plugin is used for creating a jQuery slideshow. Initially, the slideshow works correctly, but I noticed that the autoplay feature stops working when I open a new tab in Firefox or Chrome. Demo : Demo : $(document).ready(function () ...

Styling GeoJSON data in the React Leaflet mapping library can greatly enhance the

I successfully incorporated the leaflet map library into my react project. You can check it out here. I also created a geojson map component as shown below: class MapContainer extends React.Component { state = { greenIcon: { lat: 8.3114, ...