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

157
Views
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
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!