Is it possible to get the raw string value of an input with type number?
Example code
import { Component } from '@angular/core';
import { FormBuilder, FormControl } from '@angular/forms';
@Component({
selector: 'my-app',
template: `
<input
type="number"
[formControl]="control"
(ngModelChange)="getStringValue(control)"
/>
`
})
export class AppComponent {
control = this.fb.control('');
constructor(private fb: FormBuilder) {}
getStringValue(control: FormControl): void {
console.log(control.value);
}
}
Assuming I can't change the template (it's a requirement by the client) and I want to get the number of decimals or check if this number contains a decimal separator, is this possible?
When I enter 100.00
or 100.
into the input field the property control.value
contains 100
. I can't find any method like getRawValue
to access the underlying string.
I know I can suggest to change the type of the input
element to text
but first I have to find out if there are other ways to solve this.