问题
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