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

158
Visualizações
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 à 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