> ng.cmd run app:ionic-cordova-serve --host=localhost --port=8100 --
platform=browser
[ng] Compiling @angular/core : es2015 as esm2015
[ng] i 「wds」: Project is running at http://localhost:8100/webpack-dev-server/
[ng] i 「wds」: webpack output is served from /
[ng] i 「wds」: 404s will fallback to //index.html
[ng] chunk {cordova} cordova.js, cordova.js.map (cordova) 50.6 kB [entry] [rendered]
[ng] chunk {main} main.js, main.js.map (main) 1.97 kB [initial] [rendered]
[ng] chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 154 kB [initial] [rendered]
[ng] chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
[ng] chunk {styles} styles.js, styles.js.map (styles) 114 kB [initial] [rendered]
[ng] chunk {vendor} vendor.js, vendor.js.map (vendor) 340 kB [initial] [rendered]
[ng]
[ng] ERROR in Cannot read property 'map' of undefined
[ng] Date: 2020-04-12T08:00:55.810Z - Hash: 089fd22601a9cc0c5b24 - Time: 27699ms
Я не использовал переменную карты нигде в проекте. Я не могу понять эту ошибку.
Вот мой код:
import { Injectable } from "@angular/core";
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFireDatabase } from 'angularfire2/database';
import { first, map, switchMap, tap } from 'rxjs/operators';
import * as firebase from 'firebase/app';
import { of } from 'rxjs';
import { NativeStorage } from '@ionic-native/native-storage/ngx';
@Injectable({
providedIn:'root'
})
export class Presence{
id = '';
constructor(private fbAuth:AngularFireAuth,
private db:AngularFireDatabase,
private nSotrage: NativeStorage){
this.wholeMethods();
}
wholeMethods(){
this.updateOnUser().subscribe();
this.updateOnDisconnect().subscribe();
this.updateOnAway();
this.nSotrage.getItem('id').then(res=>{
this.id = res;
});
}
//get user pressence
getPresence(uid: string){
return this.db.object('Users/'+this.id).valueChanges();
// return console.log('present: ', this.db.object('status/'+this.id).valueChanges());
}
//to get userinfo
getUser(){
return this.fbAuth.authState.pipe(first()).toPromise();
}
//to set userPresence status
async setPresence(status: string){
const user = await this.getUser();
if(user){
return this.db.object('Users/'+user.uid).update({status, timestamp:this.timestamp});
}
}
get timestamp(){
return firebase.database.ServerValue.TIMESTAMP;
}
updateOnUser(){
const connection = this.db.object('.info/connected').valueChanges().pipe(
map( connected => connected ? 'online' : 'offline')
);
return this.fbAuth.authState.pipe(
switchMap(user => user ?
connection : of('offline')),
tap(status => this.setPresence(status))
);
}
updateOnAway(){
document.onvisibilitychange = (e) =>{
if(document.visibilityState == 'hidden'){
this.setPresence('away');
}else{
this.setPresence('online');
}
};
}
updateOnDisconnect(){
return this.fbAuth.authState.pipe(
tap(user =>{
if (user) {
this.db.object('Users/'+user.uid).query.ref.update({status:'offline',
timestamp:this.timestamp});
}
})
);
}
}