Ionic framework 离子2全局变量
我有一个函数,在这个函数中我有:Ionic framework 离子2全局变量,ionic-framework,ionic2,Ionic Framework,Ionic2,我有一个函数,在这个函数中我有: this.geolocation.getCurrentPosition(posOptions).then((localisation,err) => { this.storage.get('param1').then((param1) => { this.storage.get('param2').then((param2) => { // Do some stuff
this.geolocation.getCurrentPosition(posOptions).then((localisation,err) => {
this.storage.get('param1').then((param1) => {
this.storage.get('param2').then((param2) => {
// Do some stuff with localisation, param1 & param2
alert(localisation);
alert(param1);
alert(param2);
})
})
})
这是我发现的同时使用“本地化”、“param1”和“param2”的唯一方法,如果我执行以下操作:
this.geolocation.getCurrentPosition(posOptions).then((localisation,err) => {
})
this.storage.get('param1').then((param1) => {
})
this.storage.get('param2').then((param2) => {
// Do some stuff with localisation, param1 & param2
alert(localisation);
alert(param1);
alert(param2);
})
它将找不到本地化和您可以在此处使用的参数1,因为这些参数不是相互依赖的Promise.all
接受一个承诺数组,并等待所有承诺返回,然后执行,然后执行
let lPromise =this.geolocation.getCurrentPosition(posOptions);
let p1Promise = this.storage.get('param1');
let p2Promise = this.storage.get('param2');
Promise.all([lPromise,p1Promise,p2Promise])
.then((values) => {
// Do some stuff with localisation, param1 & param2
alert(values[0]);//localization
alert(values[1]);//param1
alert(values[2]);//param2
})
您可以在这里使用,因为参数不是相互依赖的Promise.all
接受一个承诺数组,并等待所有承诺返回,然后执行,然后执行
let lPromise =this.geolocation.getCurrentPosition(posOptions);
let p1Promise = this.storage.get('param1');
let p2Promise = this.storage.get('param2');
Promise.all([lPromise,p1Promise,p2Promise])
.then((values) => {
// Do some stuff with localisation, param1 & param2
alert(values[0]);//localization
alert(values[1]);//param1
alert(values[2]);//param2
})
很高兴听到:)很高兴听到:)