首页 > 解决方案 > 为什么反射元数据不是 Angular 依赖项?

问题描述

Angular 使用一些修饰构造函数的元数据来进行依赖注入。例如:

@Injectable({
  providedIn: 'root',
})
class MyService {}

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',

  styleUrls: ['./app.component.css'],
})
export class AppComponent {
  constructor(private service: MyService) {} //service will be injected using the type MyService of the param.
}

但是,如果是这样,为什么'reflect-meta-data'package.json 在生成的角度应用程序中没有依赖关系?如何在运行时获取构造函数的类型注释?

标签: angulartypescripttypesmetadatareflect-metadata

解决方案


推荐阅读