0

how can I create or inject a tree-shakable service? I cannot find any documentation about it, do you think it is correct like that?

@Injectable({
       providedIn: 'root',
})
export class ExampleService {
}


import { ExampleService } from './example.service';    
@Component({
  selector: 'app-test',
  template: ``,
  providers: { provide: AuthService,useClass: AuthService}
})
export class MyComponent {

}

in terms o performance is more efficiently use providedIn

@Injectable({
       providedIn: 'root',
})

or without providedIn

@Injectable

Thanks Andrea

Gelso77
  • 1,763
  • 6
  • 30
  • 47

1 Answers1

0

Yes, by this approach service will get loaded only for the module in which the service is instantiated. So in your case ExampleService will be loaded for the module in which MyComponent lies. FYI -link

Anand Bhushan
  • 765
  • 8
  • 18