1

I have upgraded the angular version from 1.0.8 to 1.4.0.

I have used ng-bind-html-unsafe="value | noHTML | newlines" to wrap down a string. This is not working since the new version.

I tried using the following solution, but still not working .

app.filter('unsafe', function($sce) { return $sce.trustAsHtml; });

and

ng-bind-html-unsafe="value | unsafe | noHTML | newlines"

2 Answers 2

2

Since Angular 1.2.X ng-bind-html-unsafe has been deprecated, do use ng-bind-html

ng-bind-html="value | unsafe | noHTML | newlines"
Sign up to request clarification or add additional context in comments.

5 Comments

Tried this. But not working. In this case filter('unsafe', function($sce) { return $sce.trustAsHtml; }) is required? Angular Version is 1.4.0
@ep have you included ngSanitize module in you app dependency?
No. I have'nt. Let me try that.
It is working for ng-bind-html="value | unsafe" but not for ng-bind-html="value | unsafe | noHTML | newlines".
Thanks @Pankaj. I got it working now. I'am accepting this answer as it helped me to find the solution.
1

Thanks @Pankaj Parkar:

I got it resolved now, I need to filter all. ie., to_trusted, noHTML and newlines. And also we need to get the actual value from $sce.getTrustedHtml(object)

.filter('to_trusted', ['$sce', function($sce){
    return function(text) {
        return $sce.trustAsHtml(text);
    }
}]).filter('noHTML', ['$sce', function($sce){
    return function(text) {
        var str = $sce.getTrustedHtml(text);
        str = str
        .replace(/&/g, '&')
        .replace(/>/g, '>')
        .replace(/</g, '&lt;');
        return $sce.trustAsHtml(str);
    }
}]).filter('newlines', ['$sce', function($sce){
    return function(text) {
        var str = $sce.getTrustedHtml(text);
        str =  str.replace(/\n/g, '<br/>');
        return $sce.trustAsHtml(str);
    }
}])

and

ng-bind-html="value| to_trusted | noHTML | newlines" 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.