【问题标题】:Cannot display Unicode characters in Ionic/ Angular JS无法在 Ionic/Angular JS 中显示 Unicode 字符
【发布时间】:2017-05-05 10:25:16
【问题描述】:

我在 php 中创建了一个返回 unicode 数据的 api。

 echo(json_encode($ary, JSON_UNESCAPED_UNICODE));

它只返回 ????? 但在 android 中它在接收后正确显示数据。 但离子不显示它。 可能是什么问题。

【问题讨论】:

    标签: angularjs json ionic-framework


    【解决方案1】:

    您必须使用 $sce(严格上下文转义),请参阅下面的示例

    var mOverview = angular.module('mOverview', []);
    
    mOverview.controller('mOverviewController', function ($scope, $sce) {
      $scope.mData = [
        {
            'name': '↓ '+'NASDAQ', // here the unicode is ↓ but the output is also ↓ which is supposed to be a down-arrow
            'amount': '15,698.85',
            'upDown': '+105.84'
            }
        ];
    });
    
    mOverview.filter('unsafe', function($sce) {
        return function(val) {
            return $sce.trustAsHtml(val);
        };
    });
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <div ng-app="mOverview">
      <div ng-controller="mOverviewController">
        <table>
          <tr>
            <th></th>
            <th></th>
            <th></th>
          </tr>
          <tr ng-repeat="md in mData">
            <td ng-bind-html="md.name | unsafe"></td>
            <td>{{md.amount}}</td>
            <td>{{md.upDown}}</td>
          </tr>
        </table>
     </div>

    【讨论】:

      猜你喜欢
      • 2011-12-06
      • 1970-01-01
      • 2016-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多