-2
This code below is from the one page delivery.ts file in Ionic 3.9
Neighborhood and city are data taken from an api on the localhost
Two errors are presented to me that I don’t know how to solve:
Property 'Pegcity' does not exist on type 'string'.
Property 'Pegarbairro' does not exist on type 'string'.
Code:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { HttpProvider } from '../../providers/http/http';
@IonicPage()
@Component({
selector: 'page-entrega',
templateUrl: 'entrega.html',
})
export class EntregaPage {
constructor(
public navCtrl: NavController,
public navParams: NavParams,
private httpProvider : HttpProvider) {
this.addCidade();
}
public listaCidades = [];
public listaBairros = [];
public exibirCamposText : boolean = false;
city : string;
neighborhood : string;
url = 'http://127.0.0.1/'
public PegarBairro(){
this.httpProvider.url = this.url + 'bairros' + '/cidades';
return this.httpProvider.get();
}
public PegarCidade(){
this.httpProvider.url = this.url + 'cidades';
return this.httpProvider.get();
}
public addCidade(){
this.city.PegarCidade().subscribe(
(retorno : any) =>{
this.listaCidades = retorno;
}
)
}
public clickcidade(){
this.listarBairos();
}
public listarBairos(){
this.neighborhood.PegarBairro(this.city).subscribe(
(resultado : any) =>{
this.listaBairros = resultado;
}
)
}
public clicktext(){
this.exibirCamposText = !this.exibirCamposText;
}
public resetar(){
this.city = null;
this.listaBairros = [];
this.exibirCamposText = !this.exibirCamposText;
this.addCidade();
}
}
Thanks, but how would this look if written correctly? Property 'Pegneighborhood' does not exist on type 'string'.
– jharckness
@jharckness is the same error, just look, all methods you are trying to access instead of accessing via THIS you tried to access from the variables that are strings, you did this
this.neighborhood.PegarBairro
when I should have done it:this.PegarBairro
.– Guilherme Nascimento
Thank you, everything is working.
– jharckness