在角度7中找不到“属性名称”(编译时错误)

时间:2018-12-27 12:41:29

标签: typescript angular6 angular2-services

我正在尝试将我的后端api与前端集成在一起。我遇到以下错误。 找不到名称“ cus_id”。 找不到名称“用户名”。 找不到名称“全名” .etc

期望“位置和状态”所有其他属性名称均为错误。Error

Customer.component.ts 

constructor(private fb: FormBuilder, private cs: CustomerService, private ps: ProductService) {}

  ngOnInit() {
    this.createForm();
    this.showSuccess = false;
    this.getProductList();
  }

  createForm() {
    this.customer_addForm = this.fb.group({
      username: [''],
      cus_id: [''],
      email: [''],
      fullname: [''],
      customer_currency: [''],
      mobile_primary: [''],
      website: [''],
      country: [''],
      location: [''],
      city: [''],
      postal_code: [''],
      status: [''],
      productList: ['']
    });
  }

  submitcustomeraddForm() {
    this.showSuccess = false;
    this.allProducts = _.uniq[this.allProducts];

   

    this.cs.addCustomer(username,
      cus_id, email,
      fullname,  customer_currency,
      mobile_primary,  website,
      country,  location,
       city,
      postal_code,
      status,
      productList);
  }

Customer.service.ts

export class CustomerService {

  uri = 'http://localhost:3000/customer';

  constructor(private http: HttpClient) { }

 addCustomer(username,
  cus_id, email,
  fullname,  customer_currency,
  mobile_primary,  website,
  country,  location,
   city,
  postal_code,
  status,
  productList) {

  const obj = {
    username: username,
    cus_id: cus_id,
    email: email,
    fullname: fullname,
    customer_currency:  customer_currency,
    mobile_primary:  mobile_primary,
    website:  website,
    country:  country,
    location:  location,
    city:  city,
    postal_code:  postal_code,
    status:  status,
    productList: productList
  };
    return this.http.post(`${this.uri}/add`, obj).subscribe(res => console.log('done'));
  }

我在网上搜索解决方案,但没有找到解决方案。我不知道为什么它没有显示。

1 个答案:

答案 0 :(得分:0)

您应该使用能够显示TypeScript错误的IDE。我可以推荐IntelliJ和VS Code。

enter image description here

要获取表格值,请使用例如这种语法:

this.customer_addForm.value.cus_id

编辑1:res.status