Reputation: 411
I have a shared.module
which has several services and pipes. I want to have only one instances of those services globally. If I import shared.module
inside other modules, more than one instance were created. I also tried importing shared.module
inside aap.module
but it didn't work.
Upvotes: 0
Views: 298
Reputation: 4993
It could be archived by providing service in the root without importing it into any module.
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class UserService {
}
Angular documentation has more details about providing scope.
Upvotes: 5