projects/angular/pipes/src/nl2br/nl2br.pipe.ts
Name | nl2br |
transform | ||||||
transform(value?: string | null)
|
||||||
Parameters :
Returns :
any
|
import {
Pipe,
PipeTransform,
} from '@angular/core';
@Pipe({ name: 'nl2br' })
export class UiNl2BrPipe implements PipeTransform {
transform(value?: string | null) {
return value ?
value
.replace(/\r\n/g, '<br/>')
.replace(/\r/g, '<br/>')
.replace(/\n/g, '<br/>')
:
null;
}
}