0
我在php中創建了一個返回unicode數據的api。無法在Ionic/Angular JS中顯示Unicode字符
echo(json_encode($ary, JSON_UNESCAPED_UNICODE));
它只返回?????
,但在android中,它在接收後正確顯示數據。 但Ionic不顯示它。 可能是什麼問題。
我在php中創建了一個返回unicode數據的api。無法在Ionic/Angular JS中顯示Unicode字符
echo(json_encode($ary, JSON_UNESCAPED_UNICODE));
它只返回?????
,但在android中,它在接收後正確顯示數據。 但Ionic不顯示它。 可能是什麼問題。
你將不得不使用$ 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>