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

查看:27
本文介绍了如何从 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天全站免登陆