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

159
Vistas
Decode HTML properly in input fields using AngularJS

I need to know how to properly decode HTML symbols in AngularJS for input type controls.

I am binding HTML input type='text' and textarea controls with AngularJS. The data I want to bind may contain symbols that have already been encoded and saved in database.

I know it is pretty straightforward to do this on a div or a p tags using $sce.trustAsHtml() and ng-bind-html (see below function) but I don't know how to do that for input type controls.

    app.filter('trusted', ['$sce', function ($sce) {
        var div = document.createElement('div');
        return function (text) {
            div.innerHTML = text;
            return $sce.trustAsHtml(div.textContent);
        };
    }]);

Example text from database are:

  1. Are Scotland's airports facing holiday disruption?
  2. War, pandemics and wild weather are not new, and inflation has been much higher than it is now, so why do groceries suddenly seem more expensive than ever?

I tried doing something similar (as above code), but this doesn't work.

    $scope.ConvertToHtmlText = function (text) {
        if(typeof text != typeof undefined)
            return $sce.trustAsHtml(text);
    };

    <input type="text" class="form-control xts" id="title" name="title" value="{{ConvertToHtmlText(Post.Title)}}">
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