如何从Angular范围中排除元素? [英] how can I exclude an element from an Angular scope?

查看:59
本文介绍了如何从Angular范围中排除元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的前提是错误的.虽然AngularJS肯定会减慢速度,但这并不是由于我在下面描述的问题.但是,正是flim回答了我的问题-如何从Angular范围中排除元素-能够证明这一点.

我正在建立一个站点,该站点使用d3 + Raphael从AJAX提取的数据生成图形.这会导致DOM中出现大量SVG或VML元素,具体取决于用户选择呈现哪种图表类型(例如,饼图很少,线形图和堆积条形图有很多).

I'm building a site that generates graphs using d3+Raphael from AJAX-fetched data. this results in a LOT of SVG or VML elements in the DOM, depending on what type of chart the user chooses to render (pie has few, line and stacked bar have many, for example).

我遇到了一个问题,即在AngularJS控制的文本字段中输入文本会使Firefox爬行.我输入了几个字符,然后等待2-3秒让他们突然出现,然后再输入其他字符,依此类推.(Chrome似乎可以更好地解决这个问题.)

I'm running into a problem where entering text into text fields controlled by AngularJS brings Firefox to a crawl. I type a few characters, then wait 2-3 seconds for them to suddenly appear, then type a few more, etc. (Chrome seems to handle this a bit better.)

如果页面上没有图形(用户没有提供足够的数据来生成一个图形),则可以编辑这些文本字段的内容.我假设 AngularJS在尝试更新DOM时遇到了麻烦,并且必须浏览数百个SVG或VML元素.

when there is no graph on the page (the user has not provided enough data for one to be generated), editing the contents of these text fields is fine. I assume AngularJS is having trouble when it tries to update the DOM and there's hundreds SVG or VML elements it has to look through.

但是,该图不包含AngularJS自己需要担心的任何内容.(不过,在图形之前和之后都需要注意UI元素.)

the graph, however, contains nothing that AngularJS need worry itself with. (there are, however, UI elements both before and after the graph that it DOES need to pay attention to.)

我可以想到两种解决方案:

I can think of two solutions:

  1. 将图形的DIV放在AngularJS控制器之外,并使用CSS将其定位在实际需要的位置

  1. put the graph's DIV outside the AngularJS controller, and use CSS to position it where it's actually wanted

告诉AngularJS-以某种方式-不用理会图表的DIV;在保持视图和模型同步时跳过它

tell AngularJS - somehow - to nevermind the graph's DIV; to skip it over when keeping the view and model in-sync

第二个选项对我来说似乎更可取,因为它使文档布局保持理智/语义.有什么办法吗?(或者我没有想到过的甚至更好的解决方案?)

the second option seems preferable to me, since it keeps the document layout sane/semantic. is there any way to do this? (or some, even-better solution I have not thought of?)

推荐答案

您是否尝试过ng-non-bindable? http://docs.angularjs.org/api/ng.directive:ngNonBindable

Have you tried ng-non-bindable? http://docs.angularjs.org/api/ng.directive:ngNonBindable

<ANY ng-non-bindable>
   ...
</ANY>

这篇关于如何从Angular范围中排除元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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