Pegcity does not exist in type 'string'

Asked

Viewed 104 times

-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();
    }
  }

1 answer

4

It’s a typo

In your class you have this:

city : string;

And here you tried to access the method PegarCidade() of the variable this.city:

  this.city.PegarCidade().subscribe(
    (retorno : any) =>{
      this.listaCidades = retorno;
    }
  )

But PegarCidade() is a class method EntregaPage and the correct should be:

 this.PegarCidade().subscribe(
    (retorno : any) =>{
      this.listaCidades = retorno;
    }
  )

The this.neighborhood.PegarBairro should also be this this.PegarBairro

  • Thanks, but how would this look if written correctly? Property 'Pegneighborhood' does not exist on type 'string'.

  • @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.

  • Thank you, everything is working.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.