Nidheesh
Nidheesh

Reputation: 4562

ng-bind-html-unsafe not working

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"

Upvotes: 1

Views: 2398

Answers (2)

Nidheesh
Nidheesh

Reputation: 4562

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" 

Upvotes: 1

Pankaj Parkar
Pankaj Parkar

Reputation: 136184

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

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

Upvotes: 2

Related Questions