未在角度4中显示另一个组件的搜索结果

时间:2018-01-26 14:15:21

标签: angular

在布局组件中创建了一个搜索栏。我想在另一个HTML组件中显示搜索结果。我在搜索记录时获得了空结果,并且我在服务中创建了搜索方法。

服务

ItemID   Old Cost   New Cost   Difference  Changed Date   User
--------------------------------------------------------------
2233     120        125        5           2018-01-26     Admin
2251     95         100        5           2018-01-29     Manager

layoutcomponent typescript文件

getSearchList(event) {
    const headerOptions = new Headers({'Content-Type': 'application/json', 'Authorization': 'Bearer ' +  this.authenticationService.token});
    const requestOptions = new RequestOptions({ method: RequestMethod.Get, headers: headerOptions });
    this.http.get('/api/search/' + event.target.value , requestOptions)
      .map((response: Response) => {
        console.log('data from server', response.json());
        return response.json() as Patient[];})
      .toPromise().then(x => {
        this.patientList1 = x;
        console.log('data from server', this.patientList1);
      });
  return this.patientList1;
}

searchcomponent.html

search(event: any) {
    setTimeout(() => this.ref.markForCheck());

    this.patientService.getSearchList(event);
    console.log('#####patients inside ngonit===', this.patientList1);
    this.router.navigate(['/search']);
}

下图显示了这一点 Image 请解决我的问题。

0 个答案:

没有答案