Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

108
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda