有人,能够找到我的下一个错误:
ionViewDidLoad VisualizarProfissionaisPage 获取http://localhost:3000/api/Profissionals/undefined 404(未找到)未定义
这是我从getId获取服务的地方,传递变量id
import { ListaEspecialidadesPage } from './../lista-especialidades/lista-especialidades';
import { Especialidade } from './../../models/especialidade';
import { ListaProfissionaisPage } from './../lista-profissionais/lista-profissionais';
import { Profissional } from './../../models/profissional';
import { ProfissionalServiceProvider } from './../../providers/profissionais-service';
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ViewController } from 'ionic-angular';
import { EspecialidadeServiceProvider } from './../../providers/especialidade-service';
@IonicPage()
@Component({
selector: 'page-visualizar-profissionais',
templateUrl: 'visualizar-profissionais.html',
providers: [ProfissionalServiceProvider, EspecialidadeServiceProvider]
})
export class VisualizarProfissionaisPage {
public profissional: Profissional;
public Titulo: string;
id: number;
listarProfissionais = ListaEspecialidadesPage;
constructor(public navCtrl: NavController,
public navParams: NavParams,
public viewCtrl: ViewController,
public ProfissonalServiceProvider: ProfissionalServiceProvider,
public EspecialidadeServiceProvider: EspecialidadeServiceProvider) {
this.Titulo = "Visualizar Profissionais";
this.id = navParams.get('id');
this.profissional = new Profissional();
}
ionViewDidLoad(){
console.log('ionViewDidLoad VisualizarProfissionaisPage');
this.ProfissonalServiceProvider.getId(this.id).subscribe(
data => {this.profissional = data;},
error => {console.log(error);}
);
}
}
这是我从api中获取的地方: 这没关系,因为如果我把一个数字放在id的位置,它通常需要银行
import { HttpUtilService } from './http-util-service';
import { Observable } from 'rxjs/Observable';
import { Profissional } from './../models/profissional';
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/toPromise';
import 'rxjs/add/observable/throw';
@Injectable()
export class ProfissionalServiceProvider {
apiUrl ='http://localhost:3000/api';
constructor(public http: Http, public httpUtil: HttpUtilService) {
console.log('Hello ProfissionalServiceProvider');
}
get (): Observable<Profissional> {
return this.http.get(this.apiUrl + '/Profissionals')
.map(res => res.json())
.catch((error: any) => Observable.throw(error.json.error));
}
getId(id: number): Observable<Profissional> {
return this.http.get(this.apiUrl + '/Profissionals/'+ id)
.map(res => res.json())
.catch((error: any) => Observable.throw(error.json.error));
}
}
如果你能帮助我。