ионная 3 проблема с наблюдаемой - PullRequest
0 голосов
/ 07 декабря 2018

Я новичок в 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; }'.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...