angularjs输出纯文本而不是html

我有一些这样的文字:


<span>My text</span>

我想显示不带标签的内容:


My text

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


角HTML:


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


暮色呼如
浏览 778回答 3
3回答

HUWWW

jQuery比SLOWER慢40倍左右,请不要将jQuery用于该简单任务。function htmlToPlaintext(text) {&nbsp; return text ? String(text).replace(/<[^>]+>/gm, '') : '';}用法:var plain_text = htmlToPlaintext( your_html );使用angular.js:angular.module('myApp.filters', []).&nbsp; filter('htmlToPlaintext', function() {&nbsp; &nbsp; return function(text) {&nbsp; &nbsp; &nbsp; return&nbsp; text ? String(text).replace(/<[^>]+>/gm, '') : '';&nbsp; &nbsp; };&nbsp; });使用 :<div>{{myText | htmlToPlaintext}}</div>&nbsp;&nbsp;

慕虎7371278

var app = angular.module('myapp', []);app.filter('htmlToPlaintext', function(){&nbsp; &nbsp; return function(text)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; return&nbsp; text ? String(text).replace(/<[^>]+>/gm, '') : '';&nbsp; &nbsp; };});<p>{{DetailblogList.description | htmlToPlaintext}}</p>
打开App,查看更多内容
随时随地看视频慕课网APP