javascript Angular js - 返回一个带有 HTML 字符的字符串,如
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12431125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Angular js - Return a string with HTML characters like
提问by svassr
I made a filter just to add an antislash after a value if another given value is not empty and I would like to separate this antislash from the rest of the string with
.
Actually the filter itself work but right the string " " as is in the page.
如果另一个给定的值不为空,我做了一个过滤器只是为了在一个值后添加一个反斜杠,我想将此反斜杠与字符串的其余部分分开
。实际上过滤器本身可以工作,但正确的是页面中的字符串“”。
angular.module('ngMod', []).
filter('antislash', function() {
return function(input) {
if( input==null || input.length === 0 ){
return null;
}else{
return ' / ';
}
}
});
It displays in the page : /
它显示在页面中: /
Does exist an html filter or something equivalent ?
是否存在 html 过滤器或类似的东西?
回答by svassr
It works by giving the unicodevalue for
.
它通过赋予统一的价值
。
angular.module('ngMod', []).
filter('antislash', function() {
return function(input) {
if( input==null || input.length === 0 ){
return null;
}else{
return '\u00A0/\u00A0';
}
}
});
You can also use $sanitizewith ng-bind-html
and ng-bind-html-unsafe
to output html snipets.
您还可以使用$ sanitize方法与ng-bind-html
和ng-bind-html-unsafe
输出HTML snipets。