使用类型=数字的Angular Dart材料输入问题

时间:2018-05-08 16:39:17

标签: angular dart angular-dart

我正在尝试使用来自materialDirectives的元素构建一个Web应用程序(本质上是一个在线商店),用于构建应用程序的元素。现在我正在使用后端,它将与库存数据库等一起使用。但是我认为包装有问题或者我做错了。不知道哪个,可能是我做错了,因为它在online demo上运行正常。我查看了演示的源代码,似乎无法看到我做错了什么。

所以,问题是,当我运行程序时,我收到以下错误Type 'double' is not a subtype of type 'String'。当程序使用数据库中的现有项目填充页面时,以及当我尝试更改价格,成本或库存的值时,会出现此错误。我还注意到除了'name'之外,标签和前导文本不会出现在任何输入上,除非价格,成本和库存全部为空。在我看来,Angular正在扼杀数字输入,因为它需要一个字符串,尽管事实上我明确指定了type="number"

似乎与问题相关的代码如下。

在组件的html模板中:

<material-expansionpanel-set *ngIf="!products.isEmpty">
  <material-expansionpanel *ngFor='let product of products'
    expandIcon="edit" [alwaysHideExpandIcon]="true"
    [hideExpandedHeader]="true" name='{{product.name}}'>

      <material-input floatingLabel label="Name"
        [(ngModel)]='product.name'></material-input>

      <material-input floatingLabel label="Price"
        type='number' step='0.01' checkPositive leadingText='$'
        errorMsg="Enter a valid price" [(ngModel)]='product.price'></material-input>

      <!-- ... Some similar stuff cut out here so the post wasn't a mile long ... -->

  </material-expansionpanel>
</material-expansionpanel-set>

产品类的代码:

class Product{
  final int id;
  String name;
  String description;
  double cost;
  double price;
  int stock;
  Category category;

  Product(this.id, this.name, {this.price, this.cost, this.stock, this.category, this.description});
}

模板循环的products数组只是一个Product对象数组。现在,该列表已硬编码到程序中,但随着开发的进行,显然它将从服务器获取它。

那么,我怎么能告诉它实际上期待一个数字呢?是否有一个开关或我必须设置的东西,我失踪了?没有数字输入,一切似乎都能正常工作。

0 个答案:

没有答案
相关问题