【问题标题】:How to pass the number values from angular to webapi如何将数字值从角度传递给webapi
【发布时间】:2018-06-20 16:36:44
【问题描述】:

这是我的代码 model.ts

export class Customer {
    customer_id :number
    firstname : string
    lastname : string
    email : string
    telephone : number
    password : string
}

component.ts

resetForm(form? : NgForm)
  {
    if(form!=null)
          form.reset();
      this.customerService.selectedCustomer=
      {       
        customer_id : null,
        firstname :'',
        lastname :'',
        email :'',

        password:'',
        telephone: //i want to pass 10 digit no here

      }

我想将电话号码传递给webapi form angular 5.如何实现它

【问题讨论】:

  • 这么简单telephone = 1234567890?
  • 我不想硬编码号码。我想使用动态。我有一个客户注册表,每个客户都必须输入号码
  • 所以将值绑定到某个变量或使用表单,简单!!

标签: angular asp.net-web-api


【解决方案1】:

将您的模型类更改为以下

export class Customer {
customer_id :number
firstname : string
lastname : string
email : string
telephone : string
password : string }

您可以将其作为字符串值传递给控制器​​。

那以后就算数字格式变了也很容易发帖。

resetForm(form? : NgForm)
{
  if(form!=null)
      form.reset();
  this.customerService.selectedCustomer=
   {       
    customer_id : null,
    firstname :'',
    lastname :'',
    email :'',
    password:'',
    telephone: ''
  }

【讨论】:

  • 在 Webapi 中,电话数据类型是 Phonenumber。当我在 Angular 中使用字符串并将值传递给控制器​​时,它返回一个空值。
  • Phonenumber 类型是什么?它是自定义数据类型吗?
猜你喜欢
  • 2016-10-04
  • 1970-01-01
  • 1970-01-01
  • 2018-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-06
相关资源
最近更新 更多