2014-03-26 29 views
2

來自綁定的JSON文本的字符,土耳其語字母顯示爲錯誤的編碼,例如。 &Ouml;zlem G&uuml;zelharcan它看起來像「özlemgüzelharcan」。我在頭上添加了<meta characters="utf-8">仍然沒有解決方案,並且laravel blade視圖沒有問題。使用angular-js渲染unicode-utf-8土耳其字符

如果必要的話,這是我怎麼獲得和使用數據:

觀點:

<div class="comment" ng-hide="loading" ng-repeat="comment in comments"> 
Comment #{{ comment.id }} </h3> <p>{{comment.title}}</p> 
{{comment.author_id}}/{{comment.author.name}} 

服務:

 // public/js/services/commentService.js 
    angular.module('commentService', []) 

     .factory('Comment', function($http) { 

      var data = { 
       // get all the comments 
       get : function() { 
        return $http.get('/api/comments/'); 
       } 
      } 
      console.log(data); 
      return data; 
     }); 

//controller (shortly) 
.controller('mainController', function($scope, $http, Comment) { 
     // object to hold all the data for the new comment form 
     $scope.commentData = {}; 

     // loading variable to show the spinning loading icon 
     $scope.loading = true; 

     // get all the comments first and bind it to the $scope.comments object 
     // use the function we created in our service 
     // GET ALL COMMENTS ==================================================== 
     Comment.get() 
      .success(function(data) { 
       $scope.comments = data; 
       $scope.loading = false; 
      }); 

    }); 

使用哪種方法來清潔AngularJS字符? 感謝

回答

2

最後,嘗試很多事情之後,我發現,你必須使用ng-bind-htmlng-bind-html-unsafe(與ngSanitize),以獲得正確的編碼。以下是我的看法:

Comment #<span ng-bind-template="{{comment.id}}"></span> </h3> 
     <span ng-bind-html="comment.title "></span> 
     <p><div ng-bind-html="comment.content | truncate:25"></div></p>