HI,
My App works fine in browser, but when I compile (ionic cordova build ios) this show a error in terminal: Property ‘map’ does not exist on type ‘{}’.
Ionic Framework: 3.9.2
Ionic App Scripts: 3.1.8
Angular Core: 5.0.3
Angular Compiler CLI: 5.0.3
Node: 9.3.0
OS Platform: macOS High Sierra
Navigator Platform: MacIntel
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0.3 Safari/604.5.6
checkParceirosUpdate() {
let ultimoParceiroAlterado: number;
this.storage.get('lastUpdate')
.then(lastUpdate => {
if((lastUpdate + 1800000) < Date.now()) {
console.log('Atualiza pelos 30min');
this.restProvider.getParceirosOtimize()
.then(data => {
ultimoParceiroAlterado = Math.max.apply(null, data.map(item => { // here the error (Property ‘map’ does not exist on type ‘{}’)
return new Date(item.atualizacao).getTime();
}));
this.storage.get('lastUpdate').then(lastUpdate => {
if (ultimoParceiroAlterado > lastUpdate) {
console.log('Precisa atualizar');
this.getParceiros();
this.storage.set('lastUpdate', Date.now());
} else {
console.log('não precisa atualizar');
this.storage.set('lastUpdate', Date.now());
this.storage.get('parceiros').then(parceiros => {
this.parceiros = JSON.parse(parceiros);
})
}
});
});
} else {
console.log('dentro dos 30min');
this.storage.get('parceiros').then(parceiros => {
this.parceiros = JSON.parse(parceiros);
})
}
})
}
My rest get and return:
getParceirosOtimize() {
let headers = new HttpHeaders();
headers = headers.set('Content-Type', 'application/vnd.api+json').set('accept', '*/*');
return new Promise(resolve => {
this.http.get(this.GESTORURL+'/parceiro/parceiros/otimize', { headers: headers })
.subscribe(data => {
resolve(data['data']['attributes']['otimize']); //this return a object
}, err => {
console.log(err);
});
}
);
}
Now, I know that the given return in the subscribe is a object. But how iterate with the “data.map” to make a array with all item.atualizacao value and get the maximum value of this??
And the return (data) is this:
[{"id":228,"atualizacao":"01/29/18 17:14:29","acao":"update"},{"id":205,"atualizacao":"12/16/17 12:43:47","acao":"update"},{"id":73,"atualizacao":"12/16/17 12:34:51","acao":"update"},{"id":1,"atualizacao":"12/15/17 15:35:41","acao":"update"},{"id":77,"atualizacao":"12/11/17 16:29:25","acao":"update"},{"id":69,"atualizacao":"12/11/17 16:29:25","acao":"update"}]
What did I do wrong?