Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.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/1/typescript/8.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
Angular 角度:下一个和上一个文档视图_Angular_Typescript_Routing - Fatal编程技术网

Angular 角度:下一个和上一个文档视图

Angular 角度:下一个和上一个文档视图,angular,typescript,routing,Angular,Typescript,Routing,我目前正在开发一个带有单个文档视图的搜索。 我得到了一个与我的查询匹配的所有文档ID的列表(this.hits=[“809”、“807”、“812”]) 在文档视图中,我希望导航到下一个和上一个文档。这只是第一次起作用。加载下一个文档视图时,nextItem和PreviItem未定义。我不知道为什么 我已将所有文档id存储在queryStoreService中 在DocumentViewComponent中查看单个文档 文档视图 export class DocumentViewComponen

我目前正在开发一个带有单个文档视图的搜索。 我得到了一个与我的查询匹配的所有文档ID的列表(this.hits=[“809”、“807”、“812”])

在文档视图中,我希望导航到下一个和上一个文档。这只是第一次起作用。加载下一个文档视图时,nextItem和PreviItem未定义。我不知道为什么

我已将所有文档id存储在queryStoreService中

在DocumentViewComponent中查看单个文档

文档视图

export class DocumentViewComponent implements OnInit {

    hits: string[];
    prevItem: string;
    nextItem: string;

    constructor(
        private http: HttpService,
        private route: ActivatedRoute,
        private router: Router,
        private hitsStore: QuerystoreService,

      ) {}

    ngOnInit() {
        // current Document ID
        const id = this.route.snapshot.paramMap.get('id');


        // get all ids from querysearch
        this.hits = this.hitsStore.getAllHits();

            for (let i = 0; i < this.hits.length ; i++) {
                // check if current id is in array
                if ( this.hits[i] === id ) {
                this.nextItem = this.hits[i + 1];
                this.prevItem = this.hits[i - 1];
                }
             }



            // loading single Documentview
            this.http.documentById(id).subscribe(res => {
                .....
            })


      }


      prev() {
        window.open('/document/' + this.prevItem, '_self');
        window.location.reload();
      }

      next() {
        window.open('/suche#/document/' + this.nextItem , '_self');
        window.location.reload();
      }
}

你能展示stackblitz链接吗?我从你的问题中了解到,你有一个组件,其中你的路由器参数中有id。您想加载具有此Id的http调用的内容。完成后,单击prev()和next()将导航到下一页和上一页。我说得对吗?因为您只在服务中调用getAllHits()并返回allHits。但是allHits是未定义的。你是如何得到这些回应的
export class QuerystoreService {

  allObjects: string[] = [];
  allHits: any;

  private messageSource = new BehaviorSubject('keine Query');
  currentMessage = this.messageSource.asObservable();

  constructor() { }




  gettingHits(message: any) {
    const allObjects = [];
    message.hits.forEach((hit: string) => {
      allObjects.push(hit['_id']);
  });
    console.log(allObjects);
    this.allHits = allObjects;
    return this.allObjects;
  }


  public getAllHits(): any[] {
    return this.allHits;
  }



}