我是爱奥尼克(Ionic)的新手,所以如果我问愚蠢的问题,我感到抱歉。
我正在尝试将Observable与Ionic创建的新服务一起使用。这是我的代码:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams ,AlertController} from 'ionic-angular';
import { Locations } from '../../model/Locations';
import { IftarServceProvider } from '../../providers/iftar-servce/iftar-servce';
import { Observable } from 'rxjs/observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
/**
* Generated class for the IftarplacePage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-iftarplace',
templateUrl: 'iftarplace.html',
})
export class IftarplacePage {
iftalList : Observable<Location[]>
locations:Locations={
info:'',
latitude:'',
longtiude:''
}
constructor(public navCtrl: NavController,
public navParams: NavParams,
public iftarServceProvider: IftarServceProvider,
public alertCtrl: AlertController
) {
//in this line error
this.iftalList = this.iftarServceProvider.getListLocations()
.snapshotChanges()
.map(
changes => {
return changes.map(c => ({
key: c.payload.key, ...c.payload.val()
}));
});
}
ionViewDidLoad() {
console.log('ionViewDidLoad IftarplacePage');
}
}
但是,错误是:
[ts]
Type 'Observable<{ key: string; latitude: string; longtiude: string; info: string; }[]>' is not assignable to type 'Observable<Location[]>'.
Type '{ key: string; latitude: string; longtiude: string; info: string; }[]' is not assignable to type 'Location[]'.
Type '{ key: string; latitude: string; longtiude: string; info: string; }' is not assignable to type 'Location'.
Property 'hash' is missing in type '{ key: string; latitude: string; longtiude: string; info: string; }'.