2016-11-21 50 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