Answer the question
In order to leave comments, you need to log in
How to escape all tags except br in angular?
The task is to make a line break in messages from clients.
There is a message from the client, which can contain anything, you need to replace line breaks (\n) with <br/>
.
By default, angular cuts everything, and if you use $sce, then it displays everything as html.
And I basically need to escape the message first, then replace the line breaks with <br/>
and display it as html.
I don't understand how it can be done
Answer the question
In order to leave comments, you need to log in
.filter('nl2br', ['$sce', function ($sce) {
return function (text) {
return text ? $sce.trustAsHtml(text.replace('<', '«').replace('>', '»').replace(/\n/g, '<br/>')) : '';
};
}]);
<div ng-bind-html="text | nl2br"></div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question