0

There are a lot of ways to present a html in angular.

fi use $sce.trustAsHtml(myHtmlVariable)

However, what i want to create is a such a thing:

myStringVariable = someFunction(myHtmlVariable)

Then i will be able to do some operations on my string, without html elements and attributes but just with texts. Is there such a function?

Asqan
  • 4,319
  • 11
  • 61
  • 100

1 Answers1

0

As far as i understood, there is no directly method in angular to transform html to text.

Just using DOMParser (which is working in IE10+), the following function (from another so thread) does what i needed:

function extractContent(html) {
    return (new DOMParser).parseFromString(html, "text/html") . 
        documentElement . textContent;
}
Community
  • 1
  • 1
Asqan
  • 4,319
  • 11
  • 61
  • 100