angularjs 输出纯文本而不是 html [英] angularjs to output plain text instead of html

查看:34
本文介绍了angularjs 输出纯文本而不是 html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些这样的文字:

我的文字

我想不带标签显示:

我的文字

我也不想应用标签,我想剥离它们.有什么简单的方法可以做到这一点?

角度 html:

{{myText |htmlToPlaintext}}</div>

解决方案

jQuery 约 40时间更慢,请不要使用jQuery来完成这个简单的任务.

function htmlToPlaintext(text) {返回文本?String(text).replace(/<[^>]+>/gm, '') : '';}

用法:

var plain_text = htmlToPlaintext( your_html );

<小时>

使用 angular.js :

angular.module('myApp.filters', []).过滤器('htmlToPlaintext',函数(){返回函数(文本){返回文本?String(text).replace(/<[^>]+>/gm, '') : '';};});

使用:

{{myText |htmlToPlaintext}}</div>

I have some text like this:

<span>My text</span>

I want to display without tags:

My text

I also don't want to apply the tags, I want to strip them. What's an easy way to do that?

Angular html:

<div>{{myText | htmlToPlaintext}}</div>

解决方案

jQuery is about 40 times SLOWER, please do not use jQuery for that simple task.

function htmlToPlaintext(text) {
  return text ? String(text).replace(/<[^>]+>/gm, '') : '';
}

usage :

var plain_text = htmlToPlaintext( your_html );


With angular.js :

angular.module('myApp.filters', []).
  filter('htmlToPlaintext', function() {
    return function(text) {
      return  text ? String(text).replace(/<[^>]+>/gm, '') : '';
    };
  }
);

use :

<div>{{myText | htmlToPlaintext}}</div>  

这篇关于angularjs 输出纯文本而不是 html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆