【问题标题】:Rendering unicode-utf-8 turkish characters with angular-js使用 angular-js 渲染 unicode-utf-8 土耳其语字符
【发布时间】:2014-05-04 18:25:50
【问题描述】:

来自绑定 JSON 文本的字符,土耳其语字母以错误的编码显示,例如。 Özlem Güzelharcan 看起来像“özlem gü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 使用哪种方法来清理字符? 谢谢

【问题讨论】:

    标签: javascript angularjs unicode utf-8


    【解决方案1】:

    最终,在尝试了很多事情之后,我发现你必须使用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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-02
      • 2013-08-22
      • 2014-04-16
      • 2011-03-25
      • 2014-08-09
      • 1970-01-01
      • 2015-01-07
      相关资源
      最近更新 更多