[英]Special characters in angularJs function parameter
I'm trying to call function with parameter that contains html tags and special characters: 我正在尝试使用包含html标记和特殊字符的参数调用函数:
$scope.translate is JSON like {"phrase": "phrase1"} $ scope.translate是JSON,例如{“ phrase”:“ phrase1”}
JS: JS:
$scope.t = function(phrase) {
if ($scope.translate[phrase]) {
return $scope.translate[phrase];
} else {
return phrase;
}
}
HTML: HTML:
<label class="sub-label" for="" >{{t("Fields required are marked with <span> * </ span>")}}</label>
When there are special characters - the function is not processed, but instead shows the code. 如果有特殊字符,则不会处理该功能,而是显示代码。 I guess that this is the result of processing variables in angularJS. 我猜这是在angularJS中处理变量的结果。 How do I properly solve this problem? 如何正确解决此问题?
If you have this hardcoded in your HTML template, you will need to put entities for special characters. 如果您在HTML模板中对此进行了硬编码,则需要放置用于特殊字符的实体。 This means using 这意味着使用
<label class="sub-label" for="" >{{t("Fields required are marked with <span> * </ span>")}}</label>
instead. 代替。
可能必须在您的应用程序中包含ngSanitize软件包,然后使用ngBindHtml指令 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.