问题描述
在 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 https://angular.io/guide/providers
这篇关于providedIn any 和 root 和有什么不一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!