Thanks for you reply. That’s why I don’t undestand that issue, because I’m not trying to full in anything just initialize an “empty” variable in this way:
edificio= new Edificio(0,"","");
And when I comment that line, the project compile without errors. There are no other variable with same name and I’m not calling a post or get request to the server.
app.module.ts
import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
//servicios
import { UsuarioService } from '../pages/usuario/usuario.servicio';
import { EdificioService } from '../pages/edificio/edificio.servicio';
import { HomePage } from '../pages/home/home';
import { LoginPage } from '../pages/login/login';
import { TabsPage } from '../pages/tabs/tabs';
//Import usuario
import { UsuarioPage } from '../pages/usuario/usuario';
import { CrearUsuarioPage } from '../pages/usuario/crearUsuario';
import { VerUsuarioPage } from '../pages/usuario/verUsuario';
import { EditarUsuarioPage } from '../pages/usuario/editarUsuario';
import { PopUsuarioPage } from '../pages/usuario/popUsuario';
//Import Edificio
import { EdificioPage } from '../pages/edificio/edificio';
import { CrearEdificioPage } from '../pages/edificio/crearEdificio';
/*import { VerEdificioPage } from '../pages/edificio/verEdificio';
import { EditarEdificioPage } from '../pages/edificio/editarEdificio';
import { PopEdificioPage } from '../pages/edificio/popEdificio';*/
@NgModule({
declarations: [
MyApp,
HomePage,
LoginPage,
TabsPage,
UsuarioPage,
CrearUsuarioPage,
VerUsuarioPage,
EditarUsuarioPage,
PopUsuarioPage,
EdificioPage,
CrearEdificioPage
],
imports: [
IonicModule.forRoot(MyApp),
BrowserModule,
FormsModule,
HttpModule,
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
LoginPage,
TabsPage,
UsuarioPage,
CrearUsuarioPage,
VerUsuarioPage,
EditarUsuarioPage,
PopUsuarioPage,
EdificioPage,
CrearEdificioPage
],
providers: [{provide: ErrorHandler, useClass: IonicErrorHandler},UsuarioService,EdificioService]
})
export class AppModule {}
crearEdificio.ts
import { Component } from '@angular/core';
import { NavController, NavParams,ViewController } from 'ionic-angular';
import { Edificio } from '../model/edificio';
import { EdificioService } from './edificio.servicio';
import { EdificioPage } from './edificio';
@Component({
selector: 'page-crearEdificio',
templateUrl: 'crearEdificio.html'
})
export class CrearEdificioPage
{
edificio= new Edificio(0,"","");
respuesta:any;
error:any;
constructor(public navCtrl: NavController, public navParams: NavParams, private EdificioService: EdificioService,private viewCtrl: ViewController)
{
this.respuesta=[];
this.error='';
}
//Esconde el botón back en la barra de navegación
ionViewWillEnter()
{
this.viewCtrl.showBackButton(true);
}
goBack()
{
this.navCtrl.pop();
}
}
edificio.servicio.ts
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Edificio } from '../model/edificio';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/distinctUntilChanged';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/observable/throw';
@Injectable()
export class EdificioService
{
private edificioUrl = '';
constructor (private http: Http) {}
getEdificios ():Observable<any>
{
this.edificioUrl = 'http://arrenda.api/edificio/getAll';
return this.http.get(this.edificioUrl)
.map(this.extractData)
.catch(this.handleError);
}
postCrearEdificio(body: Object):Observable<any>
{
this.edificioUrl = 'http://arrenda.api/edificio/createEdificio';
let headers = new Headers({ 'Content-Type': 'application/json; charset=UTF-8' }); // ... Set content type to JSON
let options = new RequestOptions({ headers: headers });
return this.http.post(this.edificioUrl, body, options) // ...using post request
.map(this.extractData) // ...and calling .json() on the response to return data
.catch((error:any) => Observable.throw(error));
}
postEditarEdificio(body: Object):Observable<any>
{
this.edificioUrl = 'http://arrenda.api/edificio/updateEdificio';
let headers = new Headers({ 'Content-Type': 'application/json; charset=UTF-8' }); // ... Set content type to JSON
let options = new RequestOptions({ headers: headers });
return this.http.post(this.edificioUrl, body, options) // ...using post request
.map(this.extractData) // ...and calling .json() on the response to return data
.catch((error:any) => Observable.throw(error));
}
postEliminarEdificio(body: Object):Observable<any>
{
this.edificioUrl = 'http://arrenda.api/edificio/deleteEdificio';
let headers = new Headers({ 'Content-Type': 'application/json; charset=UTF-8' }); // ... Set content type to JSON
let options = new RequestOptions({ headers: headers });
return this.http.post(this.edificioUrl, body, options) // ...using post request
.map(this.extractData) // ...and calling .json() on the response to return data
.catch((error:any) => Observable.throw(error));
}
private extractData(res: Response)
{
let body = res.json();
return body;
}
private handleError (error: Response | any) {
// In a real world app, we might use a remote logging infrastructure
let errMsg: string;
if (error instanceof Response) {
const body = error.json() || '';
const err = body.error || JSON.stringify(body);
errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
} else {
errMsg = error.message ? error.message : error.toString();
}
console.error(errMsg);
return Observable.throw(errMsg);
}
}
I think there are all the classes related with crearEdificio.ts