Updating a form control value using an Angular directive

I have implemented a custom directive to format numbers, but I am facing an issue when accessing the value using this.form.controls['montant'].value. It appears that the number is already converted to the formatted version, whereas I would prefer to access it in its original unformatted state. For example, you can see the code in action here: https://stackblitz.com/edit/angular-gzaxip

Answer №1

This is the concept behind custom directives. When a directive modifies the value within an element, the original value is no longer accessible.

To address this issue, consider reversing the operation performed by the directive when saving the value.

Alternatively, a more effective approach would be to show the formatted value in a label beside the input element and store the unchanged original value separately.

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

Ways to obtain the component reference when clicking in Angular 2?

<!--snippet from template file--> <custom-element ... other attributes (click)="handleClick()" </custom-element> @Component({ //selector and templateUrl }) class MainComponent{ handleClick(){ // Obtaining the re ...

Generic abstract class encounters failure with Typescript TypeORM findOneBy({id: id}) operation

I have incorporated the "typeorm": "^0.3.7" module. import { IRepository, EntityBase } from "core" import { Database } from "../../db" import { EntityTarget, Repository } from "typeorm" export abstract clas ...

Identifying the pressed key on a mouse click event using Angular 2

I am working on an Angular 2 component that has a div element bound to a click event: <div #myDiv class="myClass" (click)="addAnnotation($event)"> </div> When the div is clicked, I want the addAnnotation code to run only if the 'a&ap ...

Angular toolbar permanently positioned at the top of the screen

My custom toolbar, along with other components, is present in the app I'm working on. In the app.component, the structure looks something like this: <app-toolbar> </app-toolbar> <main> <a [routerLink]="['/login/en&a ...

Locate duplicate values within an array containing objects and calculate the total sum of a specified key

There is an array of objects provided in the following structure let array1 = [ { 'id': 356, 'name': 'Apple', 'quantity': 150 }, { 'id': 356, 'name': 'Apple', 'quantity& ...

How to dynamically include routes in child components using Angular 5

Below is an example of the routing structure I am working with: const routes: Routes = [ { path: '', redirectTo: '/homeapp', pathMatch: 'full'}, { path: 'homeapp', component: BasicComponent, children ...

InitAuth0 Auth0 encountering deepPartial error in Next.js with TypeScript setup

Having some trouble setting up auth0 with nextjs using typescript. When I try to initialize Auth0, I encounter an error regarding deep partials, Argument of type '{ clientId: string; clientSecret: string; scope: string; domain: string; redirectUri: st ...

Loop through the ng-content elements and enclose each one within its own individual nested div

Although it is currently not supported, I am curious to know if anyone has discovered a clever solution to this problem. In my current setup, I have a parent component with the following template: <dxi-item location='after' class="osii-item- ...

Tips for displaying items only if enough space is allocated for them using ngFor in Angular2

Is there a way I can use a custom pipe (with ngFor) to do this? At the moment I am rendering all the tags using ngFor and positioned them in a row using css flex. <div *ngFor="let tag of tags" class="tag" [ngClass]="&apo ...

The tooltip display in ng2-google-charts is not functioning properly

In my project, I am utilizing the ng2-google-charts library to generate a Timeline chart with a customized tooltip. The requirement is fairly simple - I need to display a specific value based on certain conditions. Below is the relevant code snippet: Comp ...

The Angular FormBuilder does not properly reset arrays

Whenever a user saves selected items, I want the list to be cleared. For instance, if a user selects one item and saves it, the console will display that object. But if another item is then selected and saved, both items will still appear in the console. I ...

Tips for obtaining the accurate HTML code format using Angular 2's input feature:

I am looking to retrieve all the code with an input as [input] and a tag as #tag. When attempting to obtain HTML code with jQuery using console.log($("#content")[0].outerHTML);, this is an example of how the code looks: <div dnd-droppable [dropZones]= ...

Exploring the capabilities of Mapbox in Angular version 17

After successfully loading the map style in my component, a message is displayed: import * as mapboxgl from 'mapbox-gl'; ... this.map.on('style.load', () => { this.map.loadImage(path, (err, img) => { this.message = &apos ...

switchMap: Triggering multiple requests simultaneously (2)

Currently, I am utilizing Angular 2 RC-4 and facing an issue where a network request is being triggered twice whenever there is a change in the input box. This is what my code looks like: component.ts this.term = new Control(); this.suggestions = this. ...

Utilizing Angular 4 with the highcharts gauge feature

I am currently utilizing angular 4 (4.4.4), "highcharts": "~6.0.1", "angular2-highcharts": "~0.5.5". The simple chart is displaying correctly, however I am encountering errors when trying to display the gauge chart. https://i.sstatic.net/00fby.jpg I hav ...

Strange compilation error encountered with ng-packagr due to Angular @Input inheritance

Encountering a perplexing error message in Angular 7 while working with @Input inheritance. The error message seems illogical because I have 1 mandatory @Input and 2 optional @Input, so things should align... Error: Directive MyComponent, Expected 2 argum ...

Out of nowhere, my React App has decided to stop working despite no recent changes

Hi everyone, I recently forked a React app from https://github.com/conedex/frontend. It was working perfectly fine until it suddenly stopped with this error message: ./node_modules/@metamask/utils/node_modules/superstruct/dist/index.mjs 46:43 Module parse ...

Proper communication handling with child components in small React and Typescript setups

I am looking to design a NavBar component with NavBar.Item elements that will define the buttons within the navigation bar. Here is an example of what I have in mind: <NavBar> <NavBar.Item text="Home"/> <NavBar.Item text=&q ...

The operation '*=' is not valid for the numeric values of 'number | bigint' and 'number'

I have come across this permutation function in the js-combinatorics library that I would like to customize. const _BI = typeof BigInt == 'function' ? BigInt : Number; const _crop = (n) => n <= Number.MAX_SAFE_INTEGER ? Number(n) : _BI(n); ...

Tips for passing TouchableOpacity props to parent component in React Native

I created a child component with a TouchableOpacity element, and I am trying to pass props like disabled to the parent component. Child component code: import React from 'react'; import {TouchableOpacity, TouchableOpacityProps} from 'react- ...