天天看点

关于Angular @Injectable的几种测试情况

关于Angular @Injectable的几种测试情况
关于Angular @Injectable的几种测试情况
关于Angular @Injectable的几种测试情况
关于Angular @Injectable的几种测试情况
关于Angular @Injectable的几种测试情况
关于Angular @Injectable的几种测试情况
关于Angular @Injectable的几种测试情况
关于Angular @Injectable的几种测试情况
关于Angular @Injectable的几种测试情况
关于Angular @Injectable的几种测试情况
关于Angular @Injectable的几种测试情况
关于Angular @Injectable的几种测试情况

注解 @Injectable 的作用:

Determines which injectors will provide the injectable, by either associating it with an @NgModule or other InjectorType, or by specifying that this injectable should be provided in one of the following injectors:

‘root’ : The application-level injector in most apps.

‘platform’ : A special singleton platform injector shared by all applications on the page.

‘any’ : Provides a unique instance in each lazy loaded module while all eagerly loaded modules share one instance.

Marking a class with @Injectable ensures that the compiler will generate the necessary metadata to create the class’s dependencies when the class is injected.

@Injectable 的含义是,当被注解的 class 被注入时,编译器会生成必要的元数据,以创建类的依赖。

继续阅读