简体   繁体   中英

angular 2: multiple instances of a service with different factories

Ok so basically I have the scenario where a service is very similar except for some initialization variables, which is the perfect candidate for factory.

However, I can't figure out how to use multiple services in the same component/module where each service has been initialized with a different factory?

Thanks in advance.

Service in angular 2 is a class, So you can easily do something like

let firstServiceInstance = new myServiceClass(...some arguments);
let secondServiceInstance = new myServiceClass(...some arguments);
let thiredServiceInstance = new myServiceClass(...some arguments);

And every of the above variables will hold reference to the service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM