小编Jac*_*cob的帖子

Angular 8/9 - 通过服务获取图像并将其显示在屏幕上,无需 url

我有一个返回类型文档的 api 调用:content-type
image/png

图像被发回,但没有 url,它只是发回整个图像对象。如果直接在浏览器上调用 api,它只会直接显示图像。

我希望能够有一个服务来获取此图像并将其显示在组件中。

图像数据.ts

import { Observable } from 'rxjs';

export interface ImageInfo {
    image: Image
}

export abstract class ImageData {
  abstract getImageData(): Observable<ImageInfo>;
}
Run Code Online (Sandbox Code Playgroud)

图像数据服务.ts

import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';
import { ImageInfo, ImageData } from '../data/image-data';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { throwError } from 'rxjs';
import { retry, catchError } from 'rxjs/operators';

@Injectable()
export class ImageDataService extends ImageData …
Run Code Online (Sandbox Code Playgroud)

angular angular8 angular9

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

标签 统计

angular ×1

angular8 ×1

angular9 ×1