我正在尝试在Angular5中使用ng2-completer。但是,我无法使用它发布自定义标头。我想复制this
我的HTML代码如下:
<ng2-completer [inputClass]="{'form-control': true, 'has-error': !Name.valid && Name.touched}"
[(ngModel)]="searchStr"
[datasource]="dataService"
formControlName="Name"
[minSearchLength]="3"
autoMatch="true"
clearUnselected="true"></ng2-completer>
我的组件如下:
protected searchStr: string;
headers: any;
protected dataService: RemoteData;`
constructor(private completerService: CompleterService, private url: UrlService) {
this.headers = new Headers();
const options = new RequestOptions({ headers: this.headers });
options.headers.set('Content-Type', 'application/json');
options.headers.set('Authorization', 'xxx');
this.dataService = completerService.remote(url.data_url, 'name', 'name');
this.dataRemote.requestOptions(options);
}
这个没有发送我的身份验证令牌。请任何人可以帮助我?感谢
答案 0 :(得分:0)
尝试在您的组件中执行此操作:
constructor(private completerService: CompleterService, private url: UrlService) {
this.dataService = completerService.remote(url.data_url, 'name', 'name');
let options = new RequestOptions({headers: new Headers()});
options.headers.set('Authorization','xxx');
options.headers.set('Content-Type', 'application/json');
this.dataRemote.requestOptions(options);
}
这个实现对我有用!!