特殊字符在textarea angularjs中显示为ascii字符

时间:2017-07-29 06:25:54

标签: html angularjs

实际字符串 - •恢复团队是否已组装? •SLA的关键时间 - 现在是否会受到影响,如果事件延长的时间会延长?

字符串显示在textarea中 - enter image description here

请建议..

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>

此处ng-model中的buisnessSaveCommunication是别名。

angularjs:

scope.BusinessContinutiydata.KeyMessage = scope.keyMessge;

1 个答案:

答案 0 :(得分:1)

问题是您无法在textarea / input框内直接显示已编码的实体。您可以做的是,在将值绑定到textarea之前解码它。对于使用$sanitize的{​​{1}}服务。只需将ngSanitize传递给html服务即可返回已解码的html。

&#13;
&#13;
$sanitize
&#13;
//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');
  })
&#13;
&#13;
&#13;

否则,您只需要在将值绑定到<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>之前手动解码。您可以参考What's the right way to decode a string that has special HTML entities in it?获取相同的

Demo Here

在这种情况下,我希望您使用TextAngular组件,它提供类似的功能和许多其他功能。