Prasad Shigwan
Prasad Shigwan

Reputation: 552

Special characters are displayed as ascii characters in textarea angularjs

Actual string - • Is Recovery Team assembled? • Critical timing for SLA's - are any impacted now, when will be if incident prolongs?

String getting displayed in textarea - enter image description here

Please suggest..

HTML code:

        <div class="form-group has-feedback">

            <textarea class="form-control form-control-BCC" name="Notes" ng-model="buisnessSaveCommunication.BusinessContinutiydata.KeyMessage" spellcheck="true"></textarea>

        </div>

here buisnessSaveCommunication in ng-model is alias.

angularjs :

scope.BusinessContinutiydata.KeyMessage = scope.keyMessge;

Upvotes: 1

Views: 3462

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136194

The problem is you can't directly show encoded entities inside textarea/input box. What you could do is, before binding the value to textarea decode it. For the same use $sanitize service of ngSanitize. Simply passing html to $sanitize service will return decoded html.

//Make sure you included `ngSanitize` module in your app module dependency
//Also add angular-sanitize.js with the same version that Angularjs has, otherwise it may conflict.
angular.module('app', ['ngSanitize'])
  .controller('TestCtrl', function($scope, $sce, $sanitize) {
    $scope.test = $sanitize('Critical timing for SLA&#39;s');
  })
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular-sanitize.min.js"></script>
<body ng-app="app" ng-controller="TestCtrl">
  <h1>{{test}}!</h1>
</body>


Otherwise you just need to do manually decoding before binding values to your textarea. You can refer What's the right way to decode a string that has special HTML entities in it? for the same

Demo Here


In such cases I'd prefer you to use TextAngular component, which provides similar thing with many additional feature.

Upvotes: 1

Related Questions