Search code examples
angularangular-pipe

The specified value cannot be parsed, or is out of range when using number pipe


The specified value cannot be parsed, or is out of range

When I get my object I format a number with a pipe but it returns this warning and the value isn't displayed. If I remove it, it is displayed.

This doesn't displays the value

  <input name="value" [ngModel]="value | number : '1.2-2'"/>

This displays the value

  <input name="value" [ngModel]="value"/>

TS Here I get my object by its id after choosing it in a list.

  ngOnInit(){
    this.get();
  }

get() {
    this.service.get(this.id).subscribe(
      (data) => {
        this.object = data;
        this.name = this.object.name;
        this.value = this.object.value;
      },
      (error) => {
        console.log(error);
      }
    );
  }

The value is a number and I get it in the console without any problem.


Solution

  • <input [value]="units * 600 + 2500 | number" readonly type="text" name="grandtotal"
    class="form-control" id="grandtotal" placeholder="Grand Total">
    

    I found my solution here changing or replacing the type in the HTML type="text"