2015-02-23 72 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