首页 > 解决方案 > 在角度应用程序中注入字符串有什么好处

问题描述

ng-book 中有一个关于依赖注入的很好的解释,但是关于

   import { Inject } from "@angular/core";
export class AnalyticsDemoComponent {
constructor(@Inject("API_URL") apiUrl: string) {
// works! do something w/ apiUrl
}
}

作为 DI 这样做有什么意义,与使用配置变量相比有什么好处吗?

标签: angularjstypescriptdesign-patternsdependency-injectionangular12

解决方案


推荐阅读