从管道加载图像:Angular 4

时间:2017-09-14 13:16:15

标签: angular angular-pipe

html的

<span *ngFor="let ydata of Data">
    <!-- some html -->
    <img fxFlex="85px" class="image" [src]="ydata.attachments[0].thumbnail_url | getImage>
</span>    

.pipe.ts

import { Injectable, Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { HomeService } from '../services/home/home.service';

@Pipe({ name: 'getImage' })
export class GetImagePipe implements PipeTransform {
    constructor(private _homeService: HomeService, private _sanitizer:DomSanitizer) {
    }
    transform(url: any): any {
        // this return is working
        // return '<somebase base64 string>'
        this._homeService.getImg(url).subscribe(
            res => {
                return res._body;
            },
            error => {
                return 'error';
            }
        );
    }
}    

没有得到管道的任何回复。我可以看到网络上的服务调用及其获取base64图像字符串作为服务的响应。但是,在html中,它的更新总是抛出为null。

0 个答案:

没有答案