小编Pan*_*los的帖子

Angular 2(TypeScript)处理来自Http的空json响应

我有这个功能

searching() {
 this._demoService.postData(this.url,this.searchtobesent).subscribe(
  data =>{
    this.listings=data;
    this.errorMsg="";
    if(data){
    }
    else{
      this.errorMsg="Nothing Found";
    }
  },
  error =>{
    console.log("error : "+error);
    this.errorMsg="Error Loading Your Listings";
  }
  ) ;
}
Run Code Online (Sandbox Code Playgroud)

当后端有一些结果(以Json格式发送)时,一切正常。我想要的是结果为空且我从服务器收到此消息时

[]
Run Code Online (Sandbox Code Playgroud)

我希望this.errorMsg成为找不到的东西。任何帮助,将不胜感激;)谢谢

json httphandler angular

4
推荐指数
1
解决办法
4622
查看次数

标签 统计

angular ×1

httphandler ×1

json ×1