Ignore error in the display


#1

how to make my app don’t display the error if the respond i empty?
I’m getting a list of array
my ts code

this.Http.get(this.url ).subscribe((response) => {
        this.areas = response.json();
        console.log(response)
        loadArea2.dismiss()
      if(this.areas.length !> 0){
        console.log('empty')
        let noarea2 = this.AlertController.create({
          title: 'Sorry',
          subTitle: 'No Areas in Your City',
          buttons: ['OK']
        });
        noarea2.present();
      }
      });

i want to don’t display this error and display the alert message
36%20PM


#2
  • If you are using Angular 5+'s HttpClient, there is no need to call json() on its responses
  • !> is not a valid JavaScript operator. I’m surprised this even compiled.
  • Object properties should start with lower case. Upper-case things are classes.
  • The error message implies that you are attempting to loop across an empty string using ngFor, which has nothing to do with the code you posted.
  • You shouldn’t be directly interacting with HttpClient in pages. Do that in a service provider.

#3

thank you for reply … ok but now i have ended my project and have this issue only … so i have used all my api’s in the pages … so what should i do ?