angular - 指定值无法解析,或使用数字管道时超出范围

标签 angular angular-pipe

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


当我得到我的对象时,我用管道格式化一个数字,但它返回此警告并且不显示该值。如果我删除它,它会显示出来。
这不显示值
  <input name="value" [ngModel]="value | number : '1.2-2'"/>
这显示值
  <input name="value" [ngModel]="value"/>
TS
在这里,我在列表中选择它后通过它的 id 获取我的对象。
  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);
      }
    );
  }
该值是一个数字,我在控制台中得到它没有任何问题。

最佳答案

<input [value]="units * 600 + 2500 | number" readonly type="text" name="grandtotal"
class="form-control" id="grandtotal" placeholder="Grand Total">
我发现我的解决方案在这里更改或替换 HTML type="text" 中的类型

关于angular - 指定值无法解析,或使用数字管道时超出范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65231352/

相关文章:

angular - @Input() 属性无法访问,因为它说对象在未定义的 Angular 2 中

Angular 2 CLI - 部署到 github 用户页面显示自述文件页面

Angular 4 : Store pipe output variable for use outside of template

angular - 在 Angular 2 中的对象的所有属性中搜索字符串

为输入字段选择浏览器建议时,Angular Pipe 不起作用

javascript - 如何使用 ngFor 循环复选框,以便它在 angular2 中拥有自己的索引?

angular - webpack angular2-rc5 uri.match 不是函数

javascript - 类型错误 : Cannot read property 'toLocaleLowerCase' of undefined

angular - 使用 ngrx 存储进行身份验证的路由防护

javascript - Angular 2 过滤