First of all, I have a Context
class and aSingleton
.
I would like Context
to give an instance of Http and Events to Singleton
.
import { Http } from 'angular2/http';
import { Injectable, Injector, Provider, provide } from 'angular2/core';
import { Events } from 'ionic-angular';
@Injectable()
export class Context{
constructor(private http: Http, private events: Events){}
}
export class Singleton{
private static INSTANCE: Singleton;
private context: Context;
constructor(){
if(Singleton.INSTANCE){
throw new Error();
}
let injector = Injector.resolveAndCreate([
Https,
Events
])
this.context = injector.get(Context);
}
}
However, when I compile and inspect. An error with "No provider" was raised. Thus, how could I add a provider?
Secondly, how could I use http and events in Singleton
? I suppose this.http
in Singleton
doesn't work.