2015-02-23 59 views
0

我正在做一个字符串在其中的数组ng重复。问题是一些字符串有特殊字符,如“度”和分数。下面的数组中的第一个项目的输出是“烤箱350 &#176”....而不是“烤箱350 *”。Angularjs ng-重复字符串变量与特殊字符

directions = [ 
 
\t \t \t \t "Oven 350°", 
 
\t \t \t \t "Cook potatoes in boiling salted water until done", 
 
\t \t \t \t "The next day grate potatoes coarsely", 
 
\t \t \t \t "Mix with remaining ingredients", 
 
\t \t \t \t "Place in shallow 1.5 or 2 quart baking dish and bake about 35 minutes" 
 
\t \t \t ];
<ul> 
 
    <li ng-repeat="item in directions"></li> 
 
</ul

回答

3

为了获得特殊字符工作,你需要使用ngBindHtml Documentation here

为了使用ngBindHtml你需要包括角sanitize.min.js,包括ngSanitize in your modules dependencies

Html

<div ng-controller="MyCtrl"> 
    <ul> 
    <li ng-repeat="item in directions"> 
     <span ng-bind-html='item'></span> 
    </li> 
    </ul> 
</div> 

的JavaScript

var app = angular.module('myApp', ['ngSanitize']); 

function MyCtrl($scope) { 
    $scope.directions = [ 
       "Oven 350&#176;", 
       "Cook potatoes in boiling salted water until done", 
       "The next day grate potatoes coarsely", 
       "Mix with remaining ingredients", 
       "Place in shallow 1.5 or 2 quart baking dish and bake about 35 minutes" 
      ]; 
} 

见小提琴here

+0

感谢马丁......伟大工程。 – John23 2015-02-24 00:18:31