angular - Handling null response from server -


i have ngif condition check response data. getting null response when there no data. want show "no data found " if it's null. tried ngif="!addresses" it's not working how handle this? template:

<div class="col-md-9 col-sm-9 col-xs-9 *ngif="(!addresses )">                  <div class="col-md-9 col-sm-9 col-xs-9">                 no data found                </div>           </div> 

component:

getdata(id){          this.service.getdata(id)         .subscribe(addresses => this.addresses = addresses)         this.oncehttp = !this.oncehttp;         } 

response : null service:

getdata(id){                 const eurl='http://localhost/angular/getdata.php?id='                 const url= `${eurl}${id}`                 return this.http.get(url)                 .map(this.extractdata)                 .catch(this.handleerror)              } 

i getting null value server. can tell me doing wrong??

update:

you define empty property in component follows:

getaddress(id){     this.dataservice.getaddress(id)     .subscribe(addresses => this.addresses = addresses);     this.oncehttp = !this.oncehttp;     }  empty(){    return this.addresses === null || this.addresses.length === 0; } 

then use property in template as

<div *ngif="empty">//code show when addresses has no content</div> 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -