Angularjs ng-bind-html无法使用以'<'

Angularjs ng-bind-html not working with string start with '<'

本文关键字:lt ng-bind-html Angularjs      更新时间:2023-09-26

我想使用ng-bind-html绑定一个表达式,这个表达式可以包含具有html标记("<a href='www.google.com'>google</a>")或简单字符串(名称)的字符串,正如我在这里创建的那样,http://jsfiddle.net/U3pVM/8940/

这里,location的值可以是任何字符串,当location是location2时,即以'<'开头的字符串,代码不起作用。

请帮忙。谢谢

这是因为它试图将其解析为html元素,但没有结束标记,因此没有显示任何内容。如果在末尾添加>,它将解析元素<mumbai></mumbai>

要实际显示字符,请使用编码版本&lt;,这样它就不会试图将其解析为元素。

http://jsfiddle.net/U3pVM/8941/