【问题标题】:what is diff in @Injectable() and @Inject@Injectable() 和 @Inject 的区别是什么
【发布时间】:2016-10-22 17:44:56
【问题描述】:

我正在研究 angular2 我已经创建了服务并在组件中使用 @Inject 注入了这些服务。我对在服务本身中使用 @Injectable() 以及它产生的差异感到困惑。

【问题讨论】:

标签: angular inject injectable


【解决方案1】:

@Inject() 是一种手动机制,用于让 Angular 2 知道需要注入参数

@Injectable() 让 Angular 2 知道一个类可以与依赖注入器一起使用。 @Injectable() is not strictly required 如果该类上有其他 Angular 2 装饰器。重要的是,任何将要注入 Angular 2 的类都经过修饰。

不过最好的做法是用@Injectable() 来装饰可注射物,因为这对读者来说更有意义。

【讨论】:

    猜你喜欢
    • 2016-09-15
    • 2011-11-25
    • 2011-08-18
    • 1970-01-01
    • 2020-01-09
    • 1970-01-01
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多