渲染UNI code UTF-8字符的土耳其与角的js [英] Rendering unicode-utf-8 turkish characters with angular-js
问题描述
从绑定JSON文本字符,土耳其字母显示有错误的编码如。 &放大器; Ouml; zlem G&放大器; uuml; zelharcan
这应该看起来像özlemgüzelharcan。我加了<元字符=UTF-8>
头部依然没有解决方案,并有一个与laravel刀片观点没有问题。
Characters from a binded JSON text, Turkish the letters are shown with wrong encoding for eg. Özlem Güzelharcan
which shall look like "özlem güzelharcan". I added <meta characters="utf-8">
in the head still no solution and there was no problem with laravel blade views.
如果有必要,这是我如何获得和使用数据:
If necessary this is how I get and use data:
查看:
<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字符?
谢谢
Which method is used to clean characters with AngularJS? Thanks
推荐答案
最后,尝试很多事情之后,我发现,你必须使用的 NG-绑定-HTML
或 NG-结合HTML的不安全
(与 ngSanitize
)至得到正确的编码。下面是它是如何工作在我看来:
Eventually, after trying many things, I discovered that you have to use ng-bind-html
or ng-bind-html-unsafe
(with ngSanitize
) to get the correct encoding. Here is how it works in my view:
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>
这篇关于渲染UNI code UTF-8字符的土耳其与角的js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!