Angular DI useFactory 将参数传递给工厂函数

问题描述 投票:0回答:1

如何将参数(数字)传递给工厂函数:

const id = 1;

{ provide: MyClass, useFactory: myFactory, deps: [ActivatedRoute] }


//how to pass the id here?
function myFactory(id, activatedRoute) {
...
}
angular
1个回答
0
投票

你尝试过这样的事情吗

const id = 1;

{ provide: MyClass, useFactory: (route:ActivatedRoute)=>myFactory(id,route), deps: [ActivatedRoute] }

function myFactory(id, activatedRoute) {
...
}
© www.soinside.com 2019 - 2024. All rights reserved.