0

我正在尝试在 Angular5 中使用 ng2-completer。但是我无法使用它发布自定义标题。我正在尝试复制这个

我的 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);

}

这个没有发送我的身份验证令牌。请问有人可以帮助我吗?谢谢

4

1 回答 1

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);
}

这个实现对我有用!!

于 2018-04-10T21:16:53.800 回答