$sce.getTrustedHtml(value)returntrue/false什么时候做?
When does $sce.getTrustedHtml(value) return true/false?
我很难理解 $sce.getTrustedHtml(value) return 何时为真或为假。该文档不提供信息。如果您能详细说明 return 为真和 return 为假的情况,我将不胜感激。
根据文档,$sce.getTrustedHtml(value)
的 return 值为:
The return value of $sce.getTrusted($sce.HTML, value)
基本上$sce.getTrustedHtml(value)
只是$sce.getTrusted($sce.HTML, value)
的别名。 $sce.getTrusted(context, value)
的return值为:
A version of the value that's safe to use in the given context, or throws an exception if this is impossible.
因此根据文档,它永远不会 return 为真或假(除非出于某种原因布尔值是传入值的“安全”版本)。
查看实际代码,看起来 $sce.getTrusted($sce.HTML, value)
基本上只是委托给 $sanitize(value)
,它的文档说明它 returns “sanitized HTML” 作为细绳。同样,没有布尔值。事实上,只要看一眼 $santize()
实现的代码,这些行似乎排除了布尔值 return 的任何可能性:
var buf = [];
htmlParser(html, htmlSanitizeWriter(buf, function(uri, isImage) {
return !/^unsafe:/.test($$sanitizeUri(uri, isImage));
}));
return buf.join(''); //This can't return anything except a string
所以似乎不可能从中得到一个布尔值。
我很难理解 $sce.getTrustedHtml(value) return 何时为真或为假。该文档不提供信息。如果您能详细说明 return 为真和 return 为假的情况,我将不胜感激。
根据文档,$sce.getTrustedHtml(value)
的 return 值为:
The return value of
$sce.getTrusted($sce.HTML, value)
基本上$sce.getTrustedHtml(value)
只是$sce.getTrusted($sce.HTML, value)
的别名。 $sce.getTrusted(context, value)
的return值为:
A version of the value that's safe to use in the given context, or throws an exception if this is impossible.
因此根据文档,它永远不会 return 为真或假(除非出于某种原因布尔值是传入值的“安全”版本)。
查看实际代码,看起来 $sce.getTrusted($sce.HTML, value)
基本上只是委托给 $sanitize(value)
,它的文档说明它 returns “sanitized HTML” 作为细绳。同样,没有布尔值。事实上,只要看一眼 $santize()
实现的代码,这些行似乎排除了布尔值 return 的任何可能性:
var buf = [];
htmlParser(html, htmlSanitizeWriter(buf, function(uri, isImage) {
return !/^unsafe:/.test($$sanitizeUri(uri, isImage));
}));
return buf.join(''); //This can't return anything except a string
所以似乎不可能从中得到一个布尔值。