如何从文本字符串中删除'并将其替换为'?

时间:2016-03-21 02:38:34

标签: angularjs regex wordpress

我有以下字符串:

var string = "<p>How well does Angular Work? We&#8217;re about to see!
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam vehicula 
imperdiet sapien, placerat vulputate sem bibendum id. In hac habitasse 
platea dictumst. Nulla enim lectus, laoreet non posuere at, ultricies id 
leo. Nullam nec eros lacus. Lorem ipsum dolor sit amet, consectetur 
adipiscing elit. Integer egestas scelerisque [&hellip;]</p> "

我使用以下正则表达式过滤器:

string.replace(/<\/?[^>]+>/gi, '');

然后我得到:

How well does Angular Work? We&#8217;re about to see! Lorem ipsum dolor 
sit amet, consectetur adipiscing elit. Aliquam vehicula imperdiet sapien, 
placerat vulputate sem bibendum id. In hac habitasse platea dictumst. Nulla 
enim lectus, laoreet non posuere at, ultricies id leo. Nullam nec eros 
lacus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer 
egestas scelerisque [&hellip;]

正如您所看到的,“我们”中的撇号返回&#8217;[&hellip;]位于字符串的末尾而不是[...]。我从Wordpress得到这个字符串,我想把它放在我自己的html页面中。当过滤器完成后,我应该得到:

How well does Angular Work? We're about to see! Lorem ipsum dolor sit amet, 
consectetur adipiscing elit. Aliquam vehicula imperdiet sapien, placerat 
vulputate sem bibendum id. In hac habitasse platea dictumst. Nulla enim 
lectus, laoreet non posuere at, ultricies id leo. Nullam nec eros lacus. 
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer egestas 
scelerisque. . . 

1 个答案:

答案 0 :(得分:1)

您可以使用ngBindHTML指令将html插入到指定元素的DOM中。

以下是您的示例plunker ...