Replace \n with
tag angular 6

前端 未结 2 522
遥遥无期
遥遥无期 2021-01-17 08:46

I have a REST API with \\n as backslash tags, can angular 6 replace these with
tags?

Here\'s my code:

{{x.deskrips         


        
2条回答
  •  广开言路
    2021-01-17 09:20

    You can use a pipe for the same:

    import { Pipe, PipeTransform } from '@angular/core';
    @Pipe({name: 'replaceLineBreaks'})
    export class ReplaceLineBreaks implements PipeTransform {
    transform(value: string): string {
          return value.replace(/\n/g, '
    '); } }

    The pipe must be included in your @NgModule declarations to be included in the app. To show the HTML in your template you can use the binding innerHTML.

提交回复
热议问题