Impossible to initialize Moltin as a service in Angular 2
See original GitHub issueHi guys!
I’ve been trying to use the sdk with Angular 2 (actually the 4.1.3 version) initializing the Molltin package as a service, but without success.
The following code, is the typical used to start a new project in Angular 2 very simple, but it seems that the Moltin module is not returning the necessary things to register it as a service. Or maybe the problem is that I’m actually doing something wrong (probably xD)
Every time that I tried, the app throws an error with this message:
Error: No provider for gateway!
So, a little bit of my code:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
// App modules
import { AppComponent } from './app.component';
// Moltin module
import { gateway as MoltinGateway } from '@moltin/sdk';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [
MoltinGateway
],
bootstrap: [AppComponent]
})
export class AppModule {}```
Anybody with the same problem?
Many thanks in advance!
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Angular2: Wait for service to initialize - Stack Overflow
I'm not using router (don't need it for the app), so I don't think @CanActivate is suitable in this case. Any ideas? @Component ......
Read more >Add services - Angular
Services are a great way to share information among classes that don't know each other. Create a MessageService next and inject it in...
Read more >Introduction to services and dependency injection - Angular
An injector creates dependencies and maintains a container of dependency instances that it reuses, if possible. A provider is an object that tells...
Read more >Providing dependencies in modules - Angular
A provider is an instruction to the Dependency Injection system on how to obtain a value for a dependency. Most of the time,...
Read more >Singleton services - Angular
For a sample application using the app-wide singleton service that this page ... Beginning with Angular 6.0, the preferred way to create a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@gatoenano,
In your AppModule, You must provide an instance of the gateway with your client_id, otherwise the injector wouln’t find the required dependency :
Edited: please, do not use this example. It may work, but is wrong.
Going to close this. Please reopen if you’re still have issues @gatoenano.
Thanks for the assist, @skaparate! I’m going to document your recommended Angular approach in the Wiki 🙃