Angular2 - 调用多个web api restful服务

时间:2016-11-21 16:41:18

标签: angular asp.net-web-api

是否可以在我的Angular2应用程序中调用多个服务?

我正在使用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);

    }

1 个答案:

答案 0 :(得分:0)

您是否阅读过该错误?

它表示要向CustomersController添加无参数构造函数,如下所示:

constructor() {}