Quando vou abrir a tela de cadastro me mostra esse erro. Consegui isolá-lo e descobri que ele está sendo lançado quando cria a variável private _agendamentosService: AgendamentosServiceProvider
no construtor da classe cadastro.ts. Segue abaixo meu arquivo cadastro.ts:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams} from 'ionic-angular';
import { Carro } from '../../modelos/carro';
import { AgendamentosServiceProvider } from '../../providers/agendamentos-service/agendamentos-service';
@IonicPage()
@Component({
selector: 'page-cadastro',
templateUrl: 'cadastro.html',
})
export class CadastroPage {
public carro: Carro;
public precoTotal: number;
public nome: string = '';
public endereco: string = '';
public email: string = '';
public data: string = new Date().toISOString();
constructor(
public navCtrl: NavController,
public navParams: NavParams,
private _agendamentosService: AgendamentosServiceProvider
) {
this.carro = this.navParams.get('carroSelecionado');
this.precoTotal = this.navParams.get('precoTotal');
}
agenda(){
console.log(this.nome);
console.log(this.endereco);
console.log(this.email);
console.log(this.data);
let agendamento = {
nomeCliente: this.nome,
enderecoCliente: this.endereco,
emailCliente: this.email,
modeloCarro: this.carro.nome,
precoTotal: this.precoTotal
};
this._agendamentosService.agenda(agendamento)
.subscribe(
() => alert("Agendou."),
() => alert("Não Agendou.")
);
}
}
Segue abaixo meu arquivo agendamentos-service.ts:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable()
export class AgendamentosServiceProvider {
private _url: string = 'http://localhost:8080/api';
constructor(private _http: HttpClient) {
}
agenda(agendamento){
return this._http.post(this._url + '/agendamento/agenda', agendamento);
}
}
Segue abaixo meu arquivo app.modules.ts:
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { HttpClientModule } from '@angular/common/http';
import { CarrosServiceProvider } from '../providers/carros-service/carros-service';
import { AgendamentosServiceProvider } from '../providers/agendamentos-service/agendamentos-service';
@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
HttpClientModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
CarrosServiceProvider,
AgendamentosServiceProvider
]
})
export class AppModule {}