Using typescript, In main.ts I have:
let myProvider = provide("message", { useValue: 'Hello' });
bootstrap(AppComponent, [
myProvider
]);
How can I inject this into my service (which is in a different file)? (Keep in mind I'm not using the @Component annotation.
I would use the @Inject
decorator:
@Injectable()
export class SomeService {
constructor(@Inject('message') message:string) {
}
}
Don't forget to configure the service provider. For example when bootstrapping your application:
bootstrap(AppComponent, [ SomeService, myProvider ]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With