【发布时间】:2018-01-12 02:02:09
【问题描述】:
该应用程序是使用 Ionic 3 开发的。我无法从 Firebase 检索数据。当我尝试使用函数调用 Api 时,它显示错误,它表明它没有定义.. 有什么办法可以解决这张照片。此外,ionViewDidUnload 在 Ionic 3 中不起作用。我也尝试过使用事件导入,但还是没有。
Tournaments.ts
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { TeamsPage } from '../teams/teams';
import { EliteApi } from '../../shared/elite-api'
@IonicPage()
@Component({
selector: 'page-tournaments',
templateUrl: 'tournaments.html',
})
export class TournamentsPage {
tournaments : any;
constructor(
public navCtrl: NavController,
public navParams: NavParams,
private eliteApi : EliteApi) {
}
ionViewDidLoad(){
this.eliteApi.getTournaments().then(data => this.tournaments = data );
}
itemTapped($event, tourney){
this.navCtrl.push(TeamsPage, tourney);
}
}
elite-api.ts
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
@Injectable()
export class EliteApi{
private baseUrl = 'https://elite-schedule-c1e63.firebaseio.com//';
constructor(private http: Http){}
getTournaments(){
return new Promise(resolve => {
this.http.get('${this.baseUrl}'/tournaments.json)
.subscribe((res: Response) => resolve(res.json()));
});
}
}
【问题讨论】:
标签: typescript ionic-framework ionic2 ionic3 typescript2.0