Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 操作从远程api 2获取的数据_Loops_Angular_Httprequest_Observable - Fatal编程技术网

Loops 操作从远程api 2获取的数据

Loops 操作从远程api 2获取的数据,loops,angular,httprequest,observable,Loops,Angular,Httprequest,Observable,Im接收来自Marvel api的数据,并使用ngFor显示数据。 在显示数据之前,我需要对其进行一些更改。 如果名称不存在或描述为空,我想显示一条消息 操作数据的最佳位置在哪里?如何操作 订阅后,我在我的漫画视图中尝试了类似的东西,但没有成功 If (stuff.data.results['0'].title == ''){ stuff.data.results['0'].title == 'try gain'} 我的服务 getComics(searchterm): Observabl

Im接收来自Marvel api的数据,并使用ngFor显示数据。 在显示数据之前,我需要对其进行一些更改。 如果名称不存在或描述为空,我想显示一条消息

操作数据的最佳位置在哪里?如何操作

订阅后,我在我的漫画视图中尝试了类似的东西,但没有成功

If (stuff.data.results['0'].title == ''){
stuff.data.results['0'].title == 'try gain'}
我的服务

  getComics(searchterm): Observable<any> {
    const search: URLSearchParams = new URLSearchParams();
    search.set('titleStartsWith',searchterm);
    search.set('ts', '1'); // time stamp
    search.set('apikey', 'key');
    search.set('hash', 'key');
    let obs: Observable<any> = this.http
      .get(ComicService.BASE_URL, new RequestOptions({search}))
      .map( (res) => res.json());
      console.log("obj " + obs)
    return obs;
  }
comis.html

<ul>
  <li *ngFor=" let x of stuff?.data?.results ">
    <label> Title:</label> {{x.title}}
    <br>
    <label> description: </label> {{x.description}}
    <br>
  </li>
</ul>
    标题:{x.Title}
    描述:{x.description}

我找到了一个答案:如果名称不存在或描述为空,您可以使用{{x.description | |'没有描述'}}。我仍然想知道是否可以在显示数据之前对其进行更改。我认为在angularjsI中有可能找到一个答案:如果名称不存在或描述为空,您可以使用{{x.description | | |'没有描述'}}。我仍然想知道是否有可能在显示数据之前对其进行更改。我认为这在安格拉斯是可能的
<ul>
  <li *ngFor=" let x of stuff?.data?.results ">
    <label> Title:</label> {{x.title}}
    <br>
    <label> description: </label> {{x.description}}
    <br>
  </li>
</ul>