I am trying to replicate ng-bind-html-unsafe with $sce.trustAsHtml as a filter, as given here
When I try to pass a text such as:
"Code: <?php echo strtotime($user->created_at)*1000; ?>"
it gets rendered as:
"Code: created_at)*1000; ?>"
How do I get the whole text rendered?
UPDATE:
My code is as follows:
HTML:
<p ng-bind-html="message.messagebody | newlines | unsafe"></p>
Filters:
app.filter('newlines', function () {
return function (text) {
return text.replace(/\n/g, '<br/>');
}
})
app.filter('unsafe', ['$sce',
function ($sce) {
return function (val) {
return $sce.trustAsHtml(val);
}
}
])
I am using ng-bind-html so that whenever a new line is entered, it is converted into a "<br/>" tag and displayed as a new line when rendered in the browser.
tag so that the new line is reflected when rendered in the browser. Otherwise it comes in the same line. This is why I have used ng-bind-html instead of ng-bind. – Prateek Bhatt Jul 20 '14 at 16:59