【问题标题】:Cannot find the 'property name' in angular 7 (Compile time error)在角度 7 中找不到“属性名称”(编译时错误)
【发布时间】:2018-12-27 12:41:29
【问题描述】:

我正在尝试将我的后端 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'));
  }

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

【问题讨论】:

    标签: typescript angular6 angular2-services


    【解决方案1】:

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

    要获取表单值,请使用例如这个语法:

    this.customer_addForm.value.cus_id
    

    编辑 1:res.status

    【讨论】:

    • 起初我尝试使用this.customer_addForm.value.cus_id,但没有成功
    • 所以你应该看到红色。红色的意思是,不起作用。在您的`submitcustomeraddForm()` 中创建this.customer_addForm.value 的控制台日志。你得到了什么?
    • 遇到另一个错误“Promise”类型上不存在属性“状态”。
    • ` 状态:this.customer_addForm.value.status,productList:this.allProducts }; this.cs.addCustomer(data) .subscribe( (res) => { if (res.**status**) { this.showSuccess = true ; } else { console.log('error'); } }); `
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-07
    • 2016-12-27
    • 2022-12-07
    • 2018-02-02
    • 1970-01-01
    • 2016-11-12
    • 2021-08-18
    相关资源
    最近更新 更多