Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
AngularJS Search html - only content

I have ng-bind-html directive in the html and the filter in .js file:

.filter('highlightKeywords', function($sce) {

        // returns all words in a sentence as an array, ignoring extra whitespace          
         var stringToArray = function(input) {
           if(input)
           {
             return input.match(/\S+/g);
           }
           else
           {
             return [];
           }
         };
    
        // returns regex that basically says 'match any word that starts with one of my keywords'
        var getRegexPattern = function(keywordArray) {
          var pattern = "(^|\\b)(" + keywordArray.join("|") + ")";
          return new RegExp(pattern, "gi");
        };
      
        return function(textToHighlight, keywords) {
          var filteredText = textToHighlight;
          if(keywords !== "") {
            
            var keywordList = stringToArray(keywords);
            
            var pattern = getRegexPattern(keywordList);
            console.log(pattern);
            
            filteredText = textToHighlight.replace(pattern, '<span class="highlighted">$2</span>');
          }         
          return $sce.trustAsHtml(filteredText);
        //return filteredText;
        };
    });

This solution searchs entire html (with tags). I want to search only html content. How to do that?

Thanks

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!