使用angular-js渲染unicode-utf-8土耳其字符

时间:2014-03-26 11:25:44

标签: javascript angularjs unicode utf-8

绑定的JSON文本中的字符,土耳其语字母显示错误的编码,例如。 &Ouml;zlem G&uuml;zelharcan看起来像“özlemgüzelharcan”。我在头部添加<meta characters="utf-8">仍然没有解决方案,并且laravel刀片视图没有问题。

如果有必要,这就是我获取和使用数据的方式:

视图:

<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清理字符? 感谢

1 个答案:

答案 0 :(得分: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>