Supposed I have two modules for AngularJS, e.g. foo
and bar
, and both of them define a service called baz
.
In my application I dep
When we have two services with the same name, you have to differentiate them while using it in your local module. Let's see some code below to understand how it works,
I have two Util services and need to differentiate them,
angular
.module('module1', [
])
.service('UtilService', UtilService)
.service('another.UtilService', UtilService)
.name;
In the controller file, you can simply inject like below.
export class Controller {
public static $inject: string[] = ['UtilService', 'another.UtilService'];
constructor(
private utilService: UtilService,
private anotherUtilService
) {
console.log(this.utilService) // will print the main util service methods
console.log(this.anotherUtilService) // will print the another util service
methods
}