![](/img/trans.png)
[英]How to dynamise an Observable with Restful services in angular2?
[英]Angular2 - calling multiple web api restful services
是否可以在我的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);
}
你看過這個錯誤嗎?
它說要向CustomersController
添加一個無參數構造函數,如下所示:
constructor() {}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.