admin管理员组文章数量:1353278
Trying to do angular.element(stringWithHtmlStructure);
causes
Error: Syntax error, unrecognized expression: <div id="foo">bar</div>
in jquery 1.9.1, however it works in jquery 1.8.3
Is it an issue or a feature? Security one perhaps? How do I deal with it?
1.8.3 example 1.9.1 example
It's definitely not a problem with any of the angular stuff, doing $(stringWithHtmlStructure)
fails just the same, as you can see here
Trying to do angular.element(stringWithHtmlStructure);
causes
Error: Syntax error, unrecognized expression: <div id="foo">bar</div>
in jquery 1.9.1, however it works in jquery 1.8.3
Is it an issue or a feature? Security one perhaps? How do I deal with it?
1.8.3 example http://plnkr.co/edit/ZYYKIixcYzOL46hq0puS?p=preview 1.9.1 example http://plnkr.co/edit/ETmQMY8KoCP0gaKdSrMD?p=preview
It's definitely not a problem with any of the angular stuff, doing $(stringWithHtmlStructure)
fails just the same, as you can see here http://plnkr.co/edit/FqvOKZ62t0IJ57cT05ew?p=preview
- stackoverflow./questions/14817039/… could it be this? – fxck Commented Apr 20, 2013 at 15:42
2 Answers
Reset to default 8The problem is definitely with jquery 1.9.1
HTML strings with leading whitespace: jQuery 1.9 restricts the strings processed by $() for security reasons. Although we remend you use $.parseHTML() to process arbitrary HTML like templates, the 1.1.0 version of the Migrate plugin restores the old behavior.
way to deal with it is use any kind of trimming function, whether it's jquery's $.trim or underscores trim or even your own.
Note that this problem only occurs when trying to use template from $templateCache, if you use template or templateUrl attr on the directive it works fine, I guess angular internally trims it.
If your string contains leading spaces you should remove them.
This should work:
angular.element($.trim(stringWithHtmlStructure));
本文标签: javascriptAngularjsjQuery html string parsing in 191 vs 183Stack Overflow
版权声明:本文标题:javascript - Angular.jsjQuery html string parsing in 1.9.1 vs. 1.8.3 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743927460a2563227.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论