2017-07-29 115 views
1

实际字符串 - •恢复团队是否已组装? •SLA的关键时机 - 现在是否受到影响,事件是否会延长?特殊字符在textarea中显示为ascii字符angularjs

STRING的显示在文本区域 - enter image description here

请建议..

HTML代码:

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

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

     </div> 

这里buisnessSaveCommunication在NG-模型是别名。

angularjs:

scope.BusinessContinutiydata.KeyMessage = scope.keyMessge; 
+0

代码在哪里? – 31piy

+0

@ 31piy现在增加了代码。其简单的范围值分配。但代替撇号符号显示一些ascii字符。 –

+0

请添加您正在分配的实际字符串。我的意思是scope.keyMessage –

回答

1

问题是你不能直接显示编码内textarea/input箱实体。你可以做的是,在将值绑定到textarea之前解码它。用于$sanitize服务ngSanitize。简单地通过html$sanitize服务将返回解码的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>


否则,你只需要做绑定值到您textarea之前手动解码。您可以参考What's the right way to decode a string that has special HTML entities in it?为同一

Demo Here


在这种情况下,我宁愿你们用TextAngular组件,它提供了许多额外的功能类似的事情。