Angular.js 过滤器和作用域上每秒都在变化的函数 [英] Angular.js filters and functions on scope that is changing every second

查看:23
本文介绍了Angular.js 过滤器和作用域上每秒都在变化的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题.我有一个条目表($scope.entries),每行(ng-repeat)有 5 列,其中 2 列具有用于各种转换的定制过滤器.

The problem. I have a table of entries($scope.entries), each row(ng-repeat) with 5 columns, 2 of those columns have custom made filter for various transformations.

现在在同一个范围内,我有 active_entry($scope.active_entry),它每秒钟都在变化,因为它以及 angular 的工作原理(我猜),整个范围都在不断检查并执行了我的过滤器.

Now in the same scope I have active_entry($scope.active_entry), which is changing every seconds, because of it and how angular works(I guess), the whole scope is being constantly checked and my filters executed.

这会导致 Batarang 中的观看表情随着时间的推移而飙升.

This causes Watch Expressions in Batarang to go sky high over the time.

我如何为 active_entry 创建某种隔离的范围,以便我的过滤器不会每秒一次又一次地渲染?

How can I use create some sort of isolated scope for the active_entry so my filters are not rended over and over again every second?

制定指令是创建隔离作用域的唯一方法吗?它会起作用吗?如果我稍后在控制器中需要来自隔离范围的值怎么办?

Is making a directive the only way to create an isolated scope? Would it work? What if I needed values from the isolated scope later on in the controller?

推荐答案

您在问题中提出了很多问题.最好在单独的 SO 问题中问他们每个人.

You are asking quite a few questions in your question. It would be better to ask them each in separate SO questions.

任何时候 Angular 摘要循环运行,所有监视和过滤器都会运行.改变 Angular 的内部"内容将导致消化循环运行.您如何更改 $scope.active_entry?如果您可以在 Angular 之外更改它,您也许可以做您想做的事.正如您所提到的,您还必须将该属性放入新的子作用域 (scope: true) 或隔离作用域 (scope: {...}),那么你可以调用 $scope.digest()(在你改变 active_entry 之后)来只消化那个范围.

Anytime an Angular digest cycle runs, all watches and filters will run. Changing things "inside" of Angualar will cause a digest cycle to run. How are you changing $scope.active_entry? If you can change it outside of Angular, you might be able to do what you want. As you mentioned, you'll also have to put that property into a new child scope (scope: true) or isolate scope (scope: {...}), then you could call $scope.digest() (after you change active_entry) to only digest that scope.

创建指令将是创建隔离作用域的最佳方式.您可以使用 ng-controller 或指令创建子作用域.

Creating a directive would be the best way to create an isolate scope. You can create a child scope with ng-controller or a directive.

另见https://groups.google.com/d/topic/角度/1XtEAX93ces/讨论

这篇关于Angular.js 过滤器和作用域上每秒都在变化的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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