Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在研究 angular2 我已经创建了服务并在组件中使用 @Inject 注入这些服务。我对在服务本身中使用 @Injectable() 以及它产生的差异感到困惑。
@Inject()是一种手动机制,用于让 Angular 2 知道需要注入参数
@Injectable()让 Angular 2 知道一个类可以与依赖注入器一起使用。@Injectable() is not strictly required如果该类上有其他 Angular 2 装饰器。重要的是,任何将要注入 Angular 2 的类都经过修饰。
@Injectable() is not strictly required
然而,最佳实践是使用@Injectable() 来装饰注射剂,因为这对读者来说更有意义。