2017-07-16 35 views
0

当我使用ng serve运行我的应用程序时,出现以下错误。 但我可以看到参数,参数个数是正确的。Angular 4提供的参数与呼叫目标的任何签名不匹配

src/app/Services/customer.service.ts(27,20):提供的参数不匹配调用目标的任何签名。

服务:

//With Observable 
    getCustomers(): Observable<Customer[]> { 
    console.log('getCountries Service call starting...'); 
    let apiURL = `${this.apiRoot}Customers/`; 
    return this.http.get(apiURL) 
     .map(res => 
     { 
     console.log('getCountries result: ' + res.text()); 
     return res.json().results.map(item => 
      { 
      return new Customer(
       item.CustomerID, 
       item.Username, 
       item.Password, 
       item.Email, 
       item.Firstname, 
       item.Lastname, 
       item.Address, 
       item.PostCode, 
       item.City, 
       item.OrderStatus, 
       item.FK_CountryID, 
       item.Country1, 
       item.Picture, 
       item.CreateDate 
      ); 
      } 
     ) 
     }) 
     .catch(error => { 
     console.log(error); 
     return Observable.throw(error.json()); 
     }); 
    } 

型号:

export class Customer { 
    CustomerID:number 
    Username:string 
    Password:string 
    Email:string 
    Firstname:string 
    Lastname:string 
    Address:string 
    PostCode:string 
    City:string 
    OrderStatus:string 
    FK_CountryID:number 
    Country1:string 
    Picture:string 
    CreateDate:string 
    constructor(CustomerID:number,Username:string,Password:string,Email:string,Firstname:string, 
    Lastname:string, Address:string, PostCode:string, City:string, OrderStatus:string,FK_CountryID:number, 
    Country1:string, Picture:string, CreateDate:string){ 
     this.CustomerID = CustomerID 
     this.Username = Username 
     this.Password = Password 
     this.Email = Email 
     this.Firstname = Firstname 
     this.Lastname = Lastname 
     this.Address = Address 
     this.PostCode = PostCode 
     this.City = City 
     this.FK_CountryID = FK_CountryID 
     this.Country1 = Country1 
     this.Picture = Picture 
     this.CreateDate = CreateDate 
    } 
} 
+0

'.MAP(响应=> response.json()}'将工作你为什么这样?因为 – Aravind

+0

Customer类属性在服务器端不同,所以我需要一个与设置正确的属性上一个映射有角度的一面。 –

回答

2

这很奇怪,我只是做了一个简单的变化,它的工作,我想Cli时不能正确地建立这样做的改变模型类再次构建CLI(我猜)。

所以我改变了这一点:

Country1:string, Picture:string, CreateDate:string){ 
     this.CustomerID = CustomerID 

如下(我只按后{输入):

Country1:string, Picture:string, CreateDate:string) 
{ 
    this.CustomerID = CustomerID 

所以从字面上我没有做任何改变,但强制CLI再次transpile我认为。

我也回滚了这个改变,它再次正常工作。 !?!

相关问题