Hello Friends,
One of my ionic project, am using Native Storage To Store Customer ID and Fetching It Where It Needs, by the way i have fetched from native storage successfully, and assigned to local variable and printed it also(in console). but while calling API the variable value is send as undefined. i could not track this problem long time, meanwhile this problem occurred occasionally. sometimes it have value and sometimes it happen, i have no idea about it, please help me to resolve this. Thanks in Advance.
Sample Code Structure:
…
import { NativeStorage } from ‘@ionic-native/native-storage/ngx’;
…
@Component({
…
})
export class CheckoutPage implements OnInit {
customer_id: any;
constructor(private nstore : NativeStorage) {
}
ngOnInit() {
this.getCustomerId();
confirmOrder();
}
getCustomerId(){
//get customer id from local storage
this.nstore.getItem('PROJECT_USER').then((user)=>{
console.log("Fetching Success");
console.log(user);
console.log("User ID"+user.ID);
this.customer_id=user.ID;
console.log("Customer ID"+this.customer_id);
},(error)=>{
console.log("Error Occure on Fetching Native Storage");
});
}
confirmOrder()
{
this.ds.confirmOrder(this.customer_id).subscribe((res)=>{
//here the customer id is undefined sometimes ,so i could not do futher process
....
},(err)=>{
...
})
}
}