Skip to main content
edited body
Source Link
SoluableNonagon
  • 11.8k
  • 11
  • 59
  • 100

In jQuery, if you have a string with HTML in it you can process the HTML in it and replace special characters like '&' with '&'

var myString = 'Jack & Jill';
var filtered = $('</div>').html(myString).text(); 
console.log(filtered); // outputs 'Jack & Jill'

I am writing a filter which would process HTML, but I'm depending on jQuery here, is there an AngularJS way to do it?

Here is my Filter code:

myApp.filter('filterHtmlChars', function() {
    return function(html) {
        return $('<'<div/div>'>').html(html).text(); // how could I use AngularJS here?
    };
});

PS: I already know about ng-bind-html, what I'm trying to do is filter.

In jQuery, if you have a string with HTML in it you can process the HTML in it and replace special characters like '&' with '&'

var myString = 'Jack &amp; Jill';
var filtered = $('</div>').html(myString).text(); 
console.log(filtered); // outputs 'Jack & Jill'

I am writing a filter which would process HTML, but I'm depending on jQuery here, is there an AngularJS way to do it?

Here is my Filter code:

myApp.filter('filterHtmlChars', function() {
    return function(html) {
        return $('</div>').html(html).text(); // how could I use AngularJS here?
    };
});

PS: I already know about ng-bind-html, what I'm trying to do is filter.

In jQuery, if you have a string with HTML in it you can process the HTML in it and replace special characters like '&' with '&'

var myString = 'Jack &amp; Jill';
var filtered = $('</div>').html(myString).text(); 
console.log(filtered); // outputs 'Jack & Jill'

I am writing a filter which would process HTML, but I'm depending on jQuery here, is there an AngularJS way to do it?

Here is my Filter code:

myApp.filter('filterHtmlChars', function() {
    return function(html) {
        return $('<div/>').html(html).text(); // how could I use AngularJS here?
    };
});

PS: I already know about ng-bind-html, what I'm trying to do is filter.

Source Link
SoluableNonagon
  • 11.8k
  • 11
  • 59
  • 100

AngularJS equivalent of .html() to replace html chars

In jQuery, if you have a string with HTML in it you can process the HTML in it and replace special characters like '&' with '&'

var myString = 'Jack &amp; Jill';
var filtered = $('</div>').html(myString).text(); 
console.log(filtered); // outputs 'Jack & Jill'

I am writing a filter which would process HTML, but I'm depending on jQuery here, is there an AngularJS way to do it?

Here is my Filter code:

myApp.filter('filterHtmlChars', function() {
    return function(html) {
        return $('</div>').html(html).text(); // how could I use AngularJS here?
    };
});

PS: I already know about ng-bind-html, what I'm trying to do is filter.