Angular translate: placeholder not showing special characters correctly

五迷三道 提交于 2019-12-23 17:21:38

问题


I am currently using angular-translate for a project, and it's going really well. However I run into a problem and I can't see why it's not working. I have an input field with a placeholder text, which has to be translated. This works fine, except when the translation-text includes special characters such as øæåüöä and so on.

This is my code:

<input type="text" ng-model="search.query" autofocus translate-attr-placeholder="SEARCHPLACEHOLDER" translate />
<div translate>SEARCHPLACEHOLDER</div>

when set to english it outputs:

<input placeholder="Search for magazines" (rest omitted)>
<div class="ng-scope" translate="">Search for magazines</div>

however when i set it to danish it outputs:

<input placeholder="S&#248;g i indholdet af magasiner..." (rest omitted)>
<div class="ng-scope" translate="">Søg i indholdet af magasiner...</div>

As you can see, angular translates the text in the <div> correctly, but it outputs escaped characters in the input-element.

søg 

becomes

s&#248;g

I couldn't find anything in the API. What am I missing?


回答1:


To display the special character, use $sce (Strict Contextual Escaping)

Here is the working JSFIDDLE

Hope it works :)



来源:https://stackoverflow.com/questions/32442680/angular-translate-placeholder-not-showing-special-characters-correctly

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