Angular2 Pipes: output raw HTML

后端 未结 9 2076
春和景丽
春和景丽 2020-12-13 17:43

I\'m trying to create an Angular2 custom pipe that outputs raw html. I want it to simply convert newlines in the input into HTML line breaks. How do I output raw HTML from a

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 18:12

    use angular directive

    import { Directive, ElementRef } from '@angular/core';
    
    @Directive({
        selector: '[shareLineBreaker]',
    })
    export class LineBreakerDirective {
        constructor(el: ElementRef) {
            el.nativeElement.style['white-space'] = 'pre-line'
        }
    }
    

    then

    
                        {{data.users |  arraymap:'\n':'n':'l' }}
                    
    

提交回复
热议问题