Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda