简体   繁体   English

Angular js - 返回一个包含HTML字符的字符串

[英]Angular js - Return a string with HTML characters like  

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过滤器或等效的东西?

It works by giving the unicode value for   它通过为 提供unicode值来工作  .

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 $sanitize with ng-bind-html and ng-bind-html-unsafe to output html snipets. 您还可以使用$ sanitizeng-bind-html以及ng-bind-html-unsafe来输出html snipets。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM