2014-11-26 3 views
0

HTML 문자로 post.specials 안에 데이터를 표시하려고합니다. ö 대신 'ö'를 표시하고 ngSanitize 및 ng-bind-html이 트릭을 수행해야합니까? 나는 각도 문서에서 여기html 문자 배열 안에

 <script> 
 
      function LunchBox($scope, $http) { 
 
       var url = "yahoo.com/api/callback=JSON_CALLBACK"; 
 
       $http.jsonp(url). 
 
        success(function(data) { 
 
         $scope.posts = data; 
 
        }). 
 
        error(function(data) { 
 
        }); 
 
      }; 
 

 
      angular.module('LunchBox', ['ngSanitize'], ['ui.bootstrap']); 
 
     </script>
<!doctype html> 
 
<html ng-app id="ng-app"> 
 
    <head> 
 
     <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular.min.js"></script> 
 
     <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular-sanitize.min.js"></script> 
 
     <script src="js/ui-bootstrap-tpls-0.10.0.min.js"></script> 
 
     <link href="css/bootstrap.min.css" rel="stylesheet" /> 
 
    </head> 
 
    <body> 
 
     <h1>Lunchmenu</h1> 
 
     <div id="LunchContainer" ng-app ng-controller="LunchBox"> 
 
      <div ng-repeat="post in posts | orderBy:['name']" class='postBody'> 
 
       <h2><a href='{{post.dataurl}}' class="postHeader">{{post.name}}</a></h2> 
 
       <p ng-repeat="special in post.specials" ng-bind-html="post.specials" class="postDetail"></p> 
 
      </div> 
 
     </div> 
 
    </body> 
 
</html>

+0

http://stackoverflow.com/questions/9381926/insert- : 그런 다음에보기 코드를 변경

$scope.displaySpecial = function(html) { return $sce.trustAsHtml(html); }; 

을 html-into-view-using-angularjs – qwetty

+0

@qwetty 그것이 바로 그가하고있는 일입니다. –

+0

네, 그 링크를 시도했습니다 – mapa0402

답변

1

을 뭔가를 잘못하고 있어요 : ngBindHtml

당신은 할 수있다 또한 안전 알고 값에 대한 위생을 우회. 이렇게하려면 $ sce.trustAsHtml을 통해 명시 적으로 신뢰할 수있는 값에 바인딩하십시오. 엄격한 상황 별 이스케이프 (SCE) 아래의 예를 참조하십시오. 컨트롤러에서

, $의 SCE를 주입하고 추가

<p ng-repeat="special in post.specials" 
     ng-bind-html="displaySpecial(special)" class="postDetail"> 
</p> 
+0

대단히 감사합니다. – mapa0402