AngularJS服务rootscope [英] AngularJS service rootscope

查看:119
本文介绍了AngularJS服务rootscope的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AngularJS定义的 app.factory(服务名功能($ rootScope){..})服务
如果我做 $ rootScope。$适用(),将是重新评估在应用中的所有控制器的范围或使用本服务的控制器只是范围?

I have a service defined in AngularJS with app.factory("serviceName", function($rootScope) { .. }) If I do $rootScope.$apply(), would that re-evaluate ALL the controller's scopes in the app or just the scopes of the controllers which use this service?

推荐答案

$消化()唯一的刷新当前范围及其所有子作用域。

$digest() only "flushes" the current scope and all of its child scopes.

$申请(EXP)评估记录,然后调用$消化()在根范围内。所以调用$适用()(在任何范围)影响的所有范围。

$apply(exp) evaluates the exp and then calls $digest() on the root scope. So calling $apply() (on any scope) affects all scopes.

如果你调用$消化()和你的行动改变一些父范围,改变不会被观察到。所以通常你要调用$适用()。 (如果你很想尝试,并通过调用$摘要(),它可以在以后咬你更有效率!)

If you call $digest() and your action changes some parent scope, the change will not be observed. So normally you want to call $apply(). (If you're tempted to try and be more efficient by calling $digest(), it can bite you later!)

这篇关于AngularJS服务rootscope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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