我有一个使用Ionic Geolocation和Firebase Firestore的出租车预订应用程序。我的代码无法与firestore软件包一起使用,因此我不得不将rxjs更新到版本6。它引发了错误
'Property 'filter' does not exist on type 'Observable<Geoposition>'. '
这是我的代码
import { filter } from 'rxjs/operators';
const subscription = this.geo.watchPosition()
.filter((p) => p.coords !== undefined) //Filter Out Errors
.subscribe(position => {
let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
this.map.setCenter(latLng);
this.lat = position.coords.latitude;
this.long = position.coords.longitude;
console.log(this.long + ' ' + this.lat);
});
我的package.json文件
"@ionic-native/core": "~4.15.0",
"@ionic-native/geolocation": "^4.17.0",
"@ionic-native/splash-screen": "~4.15.0",
"@ionic-native/status-bar": "~4.15.0",
"@ionic/storage": "2.2.0",
"angularfire2": "^5.1.0",
"cordova-plugin-geolocation": "^4.0.1",
"firebase": "^5.5.7",
"ionic-angular": "3.9.2",
"ionic-native": "^2.9.0",
"ionicons": "3.0.0",
"rxjs": "^6.3.3",
"rxjs-compat": "^6.3.3",
我的代码有什么问题?
答案 0 :(得分:0)
感谢@JB Nizet和@martin的贡献。我只是记得,在最新版本的rxJs中,当链接诸如过滤器和映射之类的txjs操作符时,必须使用.pipe操作符。这是我更新的代码
const subscription = this.geo.watchPosition()
.pipe(filter((p) => p.coords !== undefined)) //Filter Out Errors
.subscribe(position => {
let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
this.map.setCenter(latLng);
this.lat = position.coords.latitude;
this.long = position.coords.longitude;
console.log(this.long + ' ' + this.lat);
});