In my project, I am utilizing a json file to store key/strings for localization with angular-translate. One of the strings in this file is 'Profile & Preferences', which I am using in my view. However, when I use ng-bind-html to display this string, it renders as:
Profile & Preferences
I expected ng-bind-html to automatically convert the special character & to an ampersand. How can I ensure that it displays as &
instead of &
? I attempted changing the string value in the json file to &
, but then it appeared as:
Profile &
Preferences
Here is the tag I'm currently using:
<h3 ng-bind="'REGISTRATION_3.profile-preferences' | translate"></h3>
I have also explored approaches suggested in With ng-bind-html-unsafe removed, how do I inject HTML?.
After implementing a filter recommended in the aforementioned question:
app.filter('html', ['$sce', function ($sce) {
return function (text) {
return $sce.trustAsHtml(text);
};
}]);
The result is:
Profile &amp; Preferences
I have verified that 'ngSanitize' is being injected into my app as well.