A guide on monitoring ngForm for changes and performing calculations based on the updated values

I am encountering an issue where I am unable to retrieve the updated input value from a reactive ngForm in order to perform the necessary calculation. Please refer to my requirements outlined in the attached screenshot.

https://i.sstatic.net/IhGIZ.jpg form code:

<form #adForm="ngForm" (onSubmit)="onSubmit(adForm)">
    <table  class="table text-center">
      <thead>
        <tr>
          <th scope="col"><div class="align-middle">#</div></th>
          <th scope="col"><div class="align-middle">MonthlyFee</div></th>
          <th scope="col"><div class="align-middle">Months</div></th>
          <th scope="col"><div class="align-middle">Total Fee</div></th>
          <th scope="col"><div class="align-middle">Confirm</div></th>
        </tr>
      </thead>
      <tbody>
        <tr class="border_bottom">          
          <td class="align-middle">123</td>
          <td class="align-middle">{{ads.price | currency}}</td>
          <td class="align-middle">
            <input 
              type="number" min="1" max="12"              
              required
              class="form-control ml-4"
              id="months"
              placeholder="{{0}}"
              name="months"  
              [(ngModel)]="ads.months"            
            >
          </td>
          <td class="align-middle">{{ads.adsFee}}</td>    
          <td class="align-middle">      
            <button class="btn btn-outline-primary" (click)="onCreate()">Create</button>
          </td>           
        </tr>
      </tbody>
    </table>
  </form>

In TypeScript, I anticipate executing a simple calculation: totalFee = price * months;

Answer №1

All you have to do is:

<td class="centered">{{ads.cost * ads.duration | currency}}</td>

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

Navigating with Angular 6 - Utilizing Query Parameters within a designated secondary router outlet

Is it feasible to implement query parameters within a secondary named router outlet in Angular 6? An illustration of the desired URL format is localhost:4200/home(sidebar:chat?animal=dog) I aspire to set the query parameter "animal" and retrieve its valu ...

Maximizing the efficiency of enums in a React TypeScript application

In my React application, I have a boolean called 'isValid' set like this: const isValid = response.headers.get('Content-Type')?.includes('application/json'); To enhance it, I would like to introduce some enums: export enum Re ...

Leverage the useRef hook with React Draggable functionality

Having recently delved into coding, I find myself navigating the world of Typescript and React for the first time. My current challenge involves creating a draggable modal in React that adjusts its boundaries upon window resize to ensure it always stays wi ...

How can I customize the styling of Angular Material Datepicker?

I am currently incorporating the Angular Material Datepicker into various parts of my application. One particularly important usage is a legacy one that must remain untouched for the proper functioning of the application. This legacy Datepicker is extensiv ...

Having difficulty retrieving JSON data from a NodeJS server built with Typescript

My project involves using NodeJS + Express on the back end to send JSON data as a POST response to the front end through JQuery. I'm facing an issue where the message is not reaching the front end, which utilizes a JQuery AJAX call. It's puzzling ...

Android development offers the capability to create either Compound or Custom views that can incorporate two-way

I am looking to develop a unique Custom or Compound View in Android that combines multiple standard components and allows me to bind variables. Below is a brief example of the new control (view_custom.xml): <?xml version="1.0" encoding="utf-8"?> &l ...

Exploring TypeScript <T that belongs to any array>

getLength function appears to be functional Upon inspection, these two functions seem quite similar (The second one may be more versatile as it can handle objects with properties other than just arrays): During runtime, both functions essentially transla ...

generating declaration files for components with accurate type definitions from propTypes

I am in the process of creating a react/js library using rollup. My approach involves utilizing typescript to generate declaration files for my components. Despite having propTypes defined for my components, I have noticed that the emitted .d.ts files as ...

The error thrown is: "TypeError: device.devices.map is not a valid function

I encountered an error after adding products to the page and I'm having trouble identifying the cause. const {device} = useContext(Context) 91 | </div> > 92 | <div className="inner-display-collection"> | ^ ...

Tips on creating a literal type that is determined by a specific value within an object

In the flow, I am able to create a dynamic literal type in this manner: const myVar = 'foo' type X = { [typeof myVar]: string } const myX: X = { foo: 1 } // will throw, because number const myX: X = { foo: 'bar' } // will not throw ...

Excluding a Lazy Loaded Module from Production Build in Angular

For demonstration purposes, I have an angular module called DevShowcaseModule. However, it is crucial that this module is not included in the production build to prevent demo code errors and keep it hidden from end users. Details: Angular Version: 7.2.5 ...

Utilizing angular-in-memory-web-api for processing query parameters beyond just object properties

I currently have a collection of book objects stored in memory, book { title: string, author: string, description: string } The URL for searching books is now api/books/search/{text} The actual web API searches for matches in all attributes of the book ...

Creating custom observables by utilizing ViewChildren event and void functions in Angular 12: A step-by-step guide

I am currently working on developing a typeahead feature that triggers a service call on keyup event as the user types in an input field. The challenge I face is that my input field is enclosed within an *ngIf block, which requires me to utilize ViewChildr ...

Monitoring for adjustments in variable with RXJS

One of my classes has a boolean variable called isLoading with a default value of false. It gets set to true when a certain action (HTTP request) occurs and then back to false once the action is completed. I am interested in using RXjs to monitor this vari ...

The Angular AutoComplete feature is displaying the value as [Object Object]

In order to display the selected value in the input box and retrieve both the selected ID and value in the .ts file, I decided to bind the option value directly to [value]. However, this caused it to be printed as [Object Object] which was not my desired o ...

Unable to classify mapRef.current

I am facing an issue with my react component that contains a leaflet map. TypeScript is warning me about line mapRef.current.setView(coords, 13), stating it is an "unsafe call of an any typed value" import 'leaflet/dist/leaflet.css'; import { Map ...

What strategies can be implemented to avoid re-rendering in Angular 6 when the window is resized or loses focus?

I am currently working with a component in Angular 6.0.8 that consists of only an iframe element. Here is the code in page.component.html: <iframe [src]="url"> The logic for setting the URL is handled in page.component.ts: ngOnInit() { this.u ...

I'm having trouble understanding why I can't access the properties of a class within a function that has been passed to an Angular

Currently, I have integrated HTML 5 geolocation into an Angular component: ... export class AngularComponent { ... constructor(private db: DatabaseService) {} // this function is linked to an HTML button logCoords(message, ...

Occasionally, in Angular 8, there may be issues with data not displaying in the view (ngFor) when using array push

I have a straightforward data setup where I am using ngFor to display the data on the view. The process involves fetching all objects, pushing them into an array, and then populating them into the HTML. Everything works as expected in this setup. However ...

combine several JSON files into one JSON object with their respective file paths as keys

I have multiple JSON files that I need to merge into a single JSON file. To organize them effectively, I want to enclose each file under a unique key based on its path so that accessing specific files becomes easier in the combined JSON file. const jsonF ...