【发布时间】:2020-03-14 12:38:52
【问题描述】:
我对如何在 typescript 中使用单例类在构造函数中传递值存有疑问。
我的代码.ts
import {singleton} from "tsyringe";
@singleton()
class Foo {
constructor(data:string)
{
this.data = data
}
}
// some other file
import "reflect-metadata";
import {container} from "tsyringe";
import {Foo} from "./foo";
const instance = container.resolve(Foo);
如何使用容器.resolve函数在构造函数中传递一个值。任何人都给出了如何传递值的示例代码。
【问题讨论】:
标签: typescript typescript-typings typescript2.0 typescript-generics typescript1.5