Как вызвать функцию в том же контроллере в Angular 2, потому что это дает мне ошибку:
initialiseWeight(){
this.storage.ready().then(() => {
return this.storage.get('weightunit');
})
.then(retrievedUnit => {
if (retrievedUnit) {
this.data.weightunit = retrievedUnit;
} else {
this.data.weightunit = 'kg';
this.storage.set('weightunit', this.data.weightunit);
}
})
.catch(e => console.error('ERROR: could not read Storage Weight, error:', e));
this.storage.ready().then(() => {
return this.storage.get('realWeight');
})
.then(retrievedRealWeight => {
if (retrievedRealWeight && retrievedRealWeight!== "0" ) {
this.data.realWeight = parseInt(retrievedRealWeight, 10);
this.storage.get('userWeight').then((value) => {
this.data.userWeight = parseInt(value, 10);
});
if ( (this.data.realWeight * 1.02 < this.data.userWeight) && (!this.data.isWetsuit) ) {
this.data.userWeight = this.data.realWeight;
this.storage.set('userWeight', this.data.userWeight);
}
} else {
this.data.realWeight = 70;
this.data.userWeight = 70;
this.storage.set('realWeight', this.data.realWeight);
this.storage.set('userWeight', this.data.userWeight);
}
})
.catch(e => console.error('ERROR: could not read Storage Weight, error:', e));
}
this.initialiseWeight();