I have a REST API with \\n
as backslash tags, can angular 6 replace these with
tags?
Here\'s my code:
{{x.deskrips
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
.