All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.app.shared.pipes.thumbnail.pipe.ts Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
import { Pipe, PipeTransform } from '@angular/core';
import { SafeHtml, SafeValue } from '@angular/platform-browser';

@Pipe({
    name: 'thumbnail'
})
export class ThumbnailPipe implements PipeTransform {

    constructor() {}

    public transform(value: SafeValue): SafeHtml {
        const doc = new DOMParser().parseFromString(value.toString(), 'text/html');
        const imgElements = doc.getElementsByTagName('img');
        for (let i = 0; i < imgElements.length; i++) {
            const imgElement = imgElements.item(i);
            imgElement.classList.add('thumbnail');
            imgElement.insertAdjacentHTML('beforebegin', '' + imgElement.outerHTML + '');
            imgElement.remove();
        }
        return doc.documentElement.innerHTML;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy