如何在utf 8到日语的角度显示日语字符

时间:2015-01-09 17:20:50

标签: angularjs unicode

我正在尝试使用unicode系统来呈现正确的日语值char:

'&#x30A1'  =  ァ

所以,当我$scope.name = '&#x30A1';时,日语字符ァ没有呈现。

我应该怎么做正则表达式?像这样:

#Match Katakana

regex = u'[\u30A0-\u30FF]+' # == u'[ァ-ヾ]+'

2 个答案:

答案 0 :(得分:1)

您好我实际上使用'ngsanitize'来解决问题 这是样本

(function(angular) {
  'use strict';
  angular.module('bindHtmlExample', ['ngSanitize'])
    .controller('ExampleController', ['$scope',
      function($scope) {
        $scope.myHTML = 'I am an   &#12470  string with '

      }
    ]);
})(window.angular);
<!doctype html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Example - example-example61-production</title>

 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular-sanitize.js"></script>



</head>

<body ng-app="bindHtmlExample">
  <div ng-controller="ExampleController">
    <p ng-bind-html="myHTML"></p>
</body>

</html>

答案 1 :(得分:0)

符号&#x30A1;是HTML和XML字符引用。在JavaScript中,它只是一串八个Ascii字符,没有特殊含义。

相反,使用字符本身,如@zeroflagL在评论中建议:$scope.name = 'ァ',前提是该文件实际上是UTF-8编码并且正确声明了此编码。如果这不可行,请使用 JavaScript 表示法通过其Unicode编号引用字符:$scope.name = '\u30A1'。这与字符编码无关。