在 Angular 9 中,可注入装饰器选项 providedIn 有一个名为 any 的新值.root 和 any 有什么区别?
在我使用 any 的情况下,服务是否被视为单例?
@Injectable({providedIn: 'any'})类有用的服务{} 解决方案我认为提供的答案不是很清楚.但是,@jkonst、@schrödingcöder 和 @Bruce 在评论中是正确的.
对于 Google 发送到这里的任何人,
any 不会在每个模块中提供唯一的实例.(应该只在每个共享模块中说)
这意味着每个注入范围
中有一个实例来自
In Angular 9 the injectable decorator option providedIn has a new value called any. What is the difference between root and any?
Is a service considered a singleton in the case that I use any?
@Injectable({providedIn: 'any'}) class UsefulService { }解决方案
I think provided answers are not really clear. However, @jkonst, @schrödingcöder and @Bruce are correct in the comment.
For any one sent here by Google,
any doesn't Provides a unique instance in every module. (should say only in every shared module)
Which means one instance in every inject scope
from angular.io/guide/providers
With providedIn: 'any', all eagerly loaded modules share a singleton instance; however, lazy loaded modules each get their own unique instance, as shown in the following diagram.
更多推荐
provideIn any 和 root 有什么区别
发布评论