小编Onn*_*naB的帖子

如何获取使用 Angular5 下载的文件的名称

我的回复标题是:

HTTP/1.1 200 OK
Content-Disposition: attachment; filename="file.docx"
Accept-Ranges: bytes
Cache-Control: public, max-age=0
Last-Modified: Thu, 26 Apr 2018 10:37:00 GMT
ETag: W/"c61-16301871843"
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Content-Length: 3169
Date: Thu, 26 Apr 2018 10:37:00 GMT
Connection: keep-alive
Run Code Online (Sandbox Code Playgroud)

我试过这段代码,

 public download(id: string): Observable<Blob> {
    let headers = new Headers();
    const _baseUrl = (Api.getUrl(Api.URLS.download));
    headers.append('x-access-token', this.auth.getCurrentUser().token);
    headers.append('sale_id', id);
    return this.http.get(_baseUrl, { headers: headers, responseType: ResponseContentType.Blob})
      .map((res) => {
        console.log(res.headers) // show like in image
        return new Blob([res.blob()], { type: 'application/octet-stream' })
      });
  }
Run Code Online (Sandbox Code Playgroud)

在控制台中显示: 在此输入图像描述

没有显示内容处置! …

blob http-headers typescript angular

4
推荐指数
1
解决办法
2万
查看次数

自动完成[displayWith]不显示名称

我正在为我的项目使用自动完成材料,但我不明白如何使用 [displayWith]。我尝试了一些示例,但不在 html 中显示名称,仅显示 id。

我的html代码:

<form [formGroup]="editClientForm">
  <input formControlName="city_id" id="city_id" matInput placeholder="Select City*" aria-label="State" [matAutocomplete]="auto1"
    autoActiveFirstOption [formControl]="city">
  <mat-autocomplete #auto1="matAutocomplete" [displayWith]="displayFnCity">
    <mat-option (onSelectionChange)="updateForm($event, city.city_id, 'city_id')" *ngFor="let city of filteredOptionsCity | async"
      [value]="city.name">
      {{ city.name }}
    </mat-option>
  </mat-autocomplete>
</form>
Run Code Online (Sandbox Code Playgroud)

我的 ts 组件:

  cityid = 0;
  filteredOptionsCity: any;
  city: FormControl = new FormControl();
  editClientForm: FormGroup;
    this.editClientForm = this.fb.group({
      'city_id': new FormControl('', Validators.required),
         });
  ngOnInit() {
    this.filteredOptionsCity = this.city.valueChanges.pipe(
      startWith(''),
      map(value => this.filterCity(value))
    );
}

  populateForm() {
    this.activatedRoute.params.subscribe(
      params => {
        this.clientService.getClientById(params['id']).subscribe(
          client …
Run Code Online (Sandbox Code Playgroud)

autocomplete typescript angular-material angular

0
推荐指数
1
解决办法
5685
查看次数