2017-05-05 43 views

回答

0

你將不得不使用$ 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>

樣本