简体   繁体   中英

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

I want to bind an expression using ng-bind-html , This expression can contains string having html tag (" <a href='www.google.com'>google</a> ") or simple string (name) , as I created here , http://jsfiddle.net/U3pVM/8940/

here , value of location can be any string, when location is location2 ie a string started with '<' , code is not working.

please help. thanks.

That is because it's trying to parse it into an html element, but there's no closing tag so nothing is shown. If you add a > to the end it will parse an element <mumbai></mumbai>

To actually show the character, use the encoded version &lt; so it won't try to parse it as an element.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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