Murugan
Murugan

Reputation: 692

Without import the Angular Service to the module, can we use it?

Without import the Angular Service to the module, can we use it?

providers: [ApiService,EmployeeService,DataService,MatDatepickerModule,StudentServiceService
  ,  { provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
  { provide: MAT_DATE_FORMATS, useValue: DateFormats }],
})

here I have imported all the service classes. my question is 'Without import the Angular Service to the module, can we use it?'

Upvotes: 0

Views: 152

Answers (2)

German Cosano
German Cosano

Reputation: 107

Yes but you need to inject it where you are going to use it

Upvotes: 0

Andrei
Andrei

Reputation: 12036

with Angular 6 + you can mark services line this

@Injectable({provideIn: 'root'})
class MyService {
...
}

then you dont need to provide them explicitly

Upvotes: 2

Related Questions