2016-11-21 40 views
1

是否可以在我的Angular2應用程序中調用多個服務?Angular2 - 調用多個web api寧靜服務

我使用Http.Get使得通話,這將引發隨機錯誤,說明如下:

Message":"An error has occurred.","ExceptionMessage":"An error occurred when trying to create a controller of type 'CustomersController'. Make sure that the controller has a parameterless public constructor.","ExceptionType":"System.InvalidOperationException" 

我可以使用工具撥打服務不錯,但由於某種原因,有不同的服務的多個調用導致此問題

代碼:

public getCustomer(customerId: number): Observable<CustomerDetailResponse>{ 

     // const body = JSON.stringify(customerId); 
     const headers = new Headers();   
     headers.append('Authorization', 'eyJ');   

     let params: URLSearchParams = new URLSearchParams(); 
     params.set('customerId', customerId.toString()); 

     return this.http.get(this.serviceUrl, { headers:headers, search: params }) 
     .map((data: Response) => data.json()) 
     .debounceTime(1000) 
     .distinctUntilChanged() 
     .catch(this.handleError); 




    } 



private getLookUp(lookup: string){ 

     const body = JSON.stringify(lookup); 
     const headers = new Headers();   
     headers.append('Authorization', 'ssds');   

     return this.http.get(this.serviceUrlBase + lookup, { headers:headers }) 
     .map 
     (
      (data: Response) => data.json()   
     ) 
     .debounceTime(1000) 
     .distinctUntilChanged() 
     .catch(this.handleError); 

    } 
+0

是的,你可以調用很多的服務,但它是更好的,你將代碼粘貼 – stackdave

+0

添加代碼,如何你是消費服務 –

+0

@ stackdave代碼現在添加 – Funky

回答

0

你讀過的錯誤?

它說,一個無參數的構造函數添加到CustomersController像這樣:

constructor() {} 
+0

Typescript語法? – Igor