我正在尝试在Angular 2中实现Auto search
。我正在尝试从API获取数据以填充建议列表。我的API接受带令牌的标头。以下是一个示例网址:
curl -X GET --header 'Accept: application/json' --header 'Authorization: USERNAME PASSWORD' 'https://apsapi.azurewebsites.net/api/searchusers?searchstring=anil'
我正在使用npm ng2-completer插件。这是我的API调用:
constructor(private completerService: CompleterService, private translationService: AppTranslationService, private alertService: AlertService, private useronboardService: UserOnboard)
{
let options = new RequestOptions({ headers: new Headers() });
options.headers.set("Authorization",'Bearer0l4B9VpOnJMBzxMee8SQdU8pFW_L8wBAyQ');
let url = "https://arsapi.azurewebsites.net/api/searchusers?searchstring="
this.dataService = completerService.remote(url, 'userName', 'userName');
this.dataService.requestOptions(options);
}
我没有在请求中看到任何标题。下面是图片。
image
上面的代码会导致错误,并告知:(method)RemoteData.requestoptions(requestOptions:any):void (TS)Expected 1 arguments but got 2
。
有人可以帮助我在上面的代码中添加标题吗?