I have made a provider which uses @injectable
, its suppose to be singleton in all over the application but somehow when i console.log the data.items, they always come up empty, means it re instantiated the provider every time. Or am i missing something to make it singleton?
Anyone can please guide me
Hello,
some things you can consider me or worked to perfection
first component or principal, in this instantiate it, see below ioniBootstrap
import {SingletonX} from ‘./services/aafaf’;
@Component({
templateUrl: ‘build/xxxx.html’
})
export class ClassA {
get static parameters () {
return [
[SingletonX]];}
constructor (_singletonX) {
this._singletonX = _singletonX;
}
method () {
this._singletonX.setXXX (dddd)
}
}
ionicBootstrap (ClassA [SingletonX])
- The singleton
@Injectable ()
Const export class {
get static parameters () {
return [[Importer]];
}
constructor (_importer) {
this._importer = _importer;
this._k = new Object ();
}
setXXX (ddddd) {
this._k
}
getXXX (ddddd) {
this._k return [ddddd]
}
…
- Other component, see that is not in the provider
import {SingletonX} from ‘./services/aafaf’;
@Component ({
providers: [otherProviders],
templateUrl: ‘build / pages / xxxxx.html’
})
export OtherComponent class {
get static parameters () {
return [
[Const]];
}
constructor (_const) {
this._const = _const;
}
xMethod () {
xxx = this._const.getXXX let (xxxx);
}
…
Finally I do not speak English but look especially in not re-inject as provider, and must take into account the bootstrap.
If something comes back and asks