French accent display in Angular

梦想的初衷 提交于 2020-02-08 09:25:07

问题


I have a variable defined in my services.js file and made available to my controller via a factory. This variable contains French accents. Here is an example:

angular.module('starter.services', [])
.factory('Telephone', function() {
    var telephone = 'Téléphone';
    return {
        getVariable: function() {
            return telephone;
        }
    };
 })

The problem is, when I display my variable in the controller via the scope, the accents are not formatted properly (I get some weird characters instead). Here is my controller:

.controller('DashCtrl', function($scope, Telephone) {
    $scope.telephone = Telephone.getVariable();
    console.log('Telephone = ' + $scope.telephone); //Here I get badly formmatted accents, something like T�l�phone instead of Téléphone
})

I have also the same problem when I display the variable in HTML. I get this: T�l�phone

All my HTML templates are properly encoded (UTF-8).

Thanks in advance your help. Riadh


回答1:


You need to change é to é. So the evaluation will translate é back to é

angular.module('starter.services', [])
.factory('Telephone', function() {
    var telephone = 'Téléphone';
    return {
        getVariable: function() {
            return telephone;
        }
    };
 })


来源:https://stackoverflow.com/questions/32265485/french-accent-display-in-angular

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!