prevent AngularJS插在某些DOM层次 [英] Prevent AngularJS interpolation in certain DOM hierarchies

查看:87
本文介绍了prevent AngularJS插在某些DOM层次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用AngularJS并有HTML,我不希望插值,因为它包含用户输入数据的某些部分。因此,潜在的数据可能有 {{} ASDF} 在那里,我不想AngularJS解析。这是因为如果用户输入 {{{} {}} 这可能打破的编制过程和prevent运行任何角度code。

有没有解决的办法通过指定角不编译DOM树的这一部分?


解决方案

非可绑定指令我相信是你想找的。

因此​​,在任何元素你可以这样做:

 < D​​IV NG-非绑定>一些{{1 + 2}的前pressions< / DIV>

这将显示:

 部分{{1 + 2}的前pressions

I use AngularJS and have some parts of HTML that I don't wish to interpolate because it contains user inputted data. So potentially the data may have {{asdf}} in there that I don't want AngularJS to parse. This is because if the user inputs {{{}, {}} this may break the compilation process and prevent any Angular code from running.

Is there a way around this by specifying to Angular not to compile this part of the DOM tree?

解决方案

The Non Bindable directive I believe is what your looking for.

So at any element you can do:

<div ng-non-bindable> Some {{1+2}} expressions</div>

That will display:

Some {{1+2}} expressions

这篇关于prevent AngularJS插在某些DOM层次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆