Tips for storing information without using ngModel in template-driven methodology

Currently facing a dilemma where data needs to be saved to the database from Angular UI. The display format of tabular data changes dynamically based on dropdown selections, without having predefined model properties for binding.

The question arises: How can data be saved to the database without a defined model class with properties for binding? Creating over 100+ properties seems excessive, especially when the number of values displayed in the UI is unknown.

For instance, if the dropdown has options A, B, C, D, each resulting in different numbers of rows being returned (15, 30, 50...), how can this data be efficiently saved?

The code snippet below showcases how the data is fetched and displayed in a tabular format:

.ts

// JavaScript code here

.html

<table class="tableInfo">
    // HTML table structure here
</table>

Data display is successful, but the challenge remains on how to save the data without a model. With potentially multiple rows that can be edited, the existing dirty property might not suffice. Is there an alternative solution for saving the data or is creating a model class with ngmodel the only way forward?

Answer №1

If you're feeling adventurous, instead of taking the easy route with ReactiveForms or a simple array of row models, you can choose to tackle it the hard way...

Why not wrap everything in a <form> and stick to good old HTML form submissions?

<form action="some/backend/path" method="POST">
   Place your table with inputs here - just ensure each has a unique `name` attribute as you are duplicating them now

<button type="submit">GO FOR IT</button>
</form>

If you need to manipulate the form/data before submission, you can always utilize the onsubmit event.

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

Receiving a notification when attempting to log in with incorrect credentials

I am currently working on an Angular login page implementation using a username and password setup. When the user enters incorrect credentials, I want to display an alert message indicating the same. Here is the HTML code snippet for the form: <form [f ...

Having trouble retrieving response headers in Angular 5

After sending a post request to a server, I receive a response with two crucial headers for the client: username and access-token. The Chrome debug tool's Network Tab displays the data from the response like this: In addition, I attempt to log the re ...

I possess an item that I must display its title as a <choice> in a <menu> while returning a different variable

I am working with an object: company: { name: 'Google', id: '123asd890jio345mcn', } My goal is to display the company name as an option in a material-ui selector (Autocomplete with TextField rendering). However, when a user selects ...

Tips for utilizing mergeWith with Subjects in an Angular application

Objective: Creating a Combined Filter with 3 Inputs to refine a list Conditions: Users are not required to complete all filters before submission The first submit occurs when the user inputs data Inputs are combined after more than one is provided Appro ...

Angular 5 Web-Based EPUB Reader

Just getting started with Angular 5 and I'm looking to display an epub file on a page without resorting to iframes. Any suggestions on how to achieve this? ...

After upgrading from angular version 7.0 to 8.0, I realized that the target in the tsconfig.json file remained unchanged

After running the command ng update @angular/cli @angular/core, I successfully updated my Angular 8 version. The updated versions are as follows: Angular CLI: 8.0.1 Node: 10.15.3 OS: linux x64 Angular: 8.0.0 ... animations, cdk, common, compiler, compiler ...

Finding the row index in an Angular material table

How can I retrieve the row index in an Angular material table? <td mat-cell *matCellDef="let row"> <mat-checkbox (click)="$event.stopPropagation()&quo ...

The directive within the module was not carried out

After setting up a fresh module in my Angular 8 project and adding a new directive to it, nothing seemed to happen at runtime (although the compilation was successful). I even added console logs to the directive to check if it was being executed different ...

Does Typescript fail to recognize the "delete" operator?

Whenever I utilize the delete operator in Typescript, it appears that the system does not recognize that the property has been eliminated. For instance: interface HasName { name: string; } interface HasNoName { name: never; } function removeName( ...

Tips for using MatTableDataSource in a custom Thingsboard widget

After creating multiple custom Thingsboard widgets, I've discovered that I can access a significant portion of @angular/material within my widget code. While I have successfully implemented mat-table, I now want to incorporate pagination, filtering, a ...

By default, all groups in the Kendo UI Angular 2 Grid are collapsed

Just started using the new Kendo UI for Angular 2 Grid and I have a question - is it possible to collapse all groups by default when grouping data? I noticed there is a method called collapseGroup(), but it's unclear how to use it or if there's ...

Is there a way to customize the default MuiCheckbox icon in theme.ts?

How can I customize the icon default prop for Mui checkbox? I followed the instructions provided here and used a snippet from the documentation: const BpIcon = styled('span')(({ theme }) => ({ borderRadius: 3, width: 16, height: 16, .. ...

A guide on transferring files to a PHP server using HttpClient and FormData within an Ionic framework, along with instructions on receiving files in PHP

I have an input file in mypage.html on Ionic and I want to send this file to PHP for uploading it onto the server. In mypage.page.html, I have created an input field for the file name and another input field for the file to be uploaded. <ion-header> ...

Explore visuals in the component repository

I am currently working on an Angular 7 component library and am facing some challenges in adding images for buttons and other elements. My project structure is organized as follows: projects components src lib myComponent assets ...

Are there more efficient alternatives to utilizing arrays and index-based functions for storing in-memory data in TypeScript?

Is there a more efficient method for storing and retrieving data besides relying on Array index-based calls? For instance: export interface EntityInterface { id: number; name: string; age: number; } export class ClassName { entities: Enti ...

The execution of *ngSwitchCase in Angular seems to be faulty

I am new to Angular and currently working with the ngSwitch directive in my program. However, I have encountered an issue where *ngSwitchDefault is executing instead of *ngSwitchCase every time the program runs. Below is the code snippet that I am using: ...

Angular 7 ERROR: The SystemJS reference is missing

In the process of developing an Angular 7 project with systemjs for dynamic module loading, I encountered an issue. Upon attempting to utilize it, I encountered the following error: ERROR ReferenceError: SystemJS is not defined Within my package.json f ...

Avoid changing the button color to a lighter shade when it is clicked

Is there a way to prevent button text from changing to a lighter color after clicking? I am facing an issue where the button I set to red turns slightly whiteish after it is clicked. How can I ensure that the button stays red at all times? Header Toolbar ...

Could someone show me how to modify the color of Material UI Label text in Angular?

Currently, I am developing my Angular university Project using the Mui library. In my logIn form, I have a Dark background and I would like to change the color of my Label Textfield to something different. Can anyone provide assistance? ...

Angular 11 reactive form not reflecting real-time changes in input field

I'm currently working on an Angular project and I need to dynamically update a reactive form field with data retrieved from an API called getNextCode(). I have a function that calls the API service like this: ngOnInit(): void { this.NextCodeService.g ...