首页 > 解决方案 > 以角度返回一个空数组

问题描述

我有一个作为 getSectionDetails 的服务调用。当我在 component.ts 类中调用它时,它只返回一个空数组。我正在从上一页获取 eventId。它将在控制台中打印。所以进入下一页(节页)是没有问题的。我需要通过 getSectionDetail 调用发送 eventId。当我进入版块页面时,我需要获取版块详细信息。但在这种情况下,当我进入部分页面时,它返回一个空数组

import {AfterViewInit, OnDestroy} from '@angular/core';
import {Component, ViewEncapsulation, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {Section} from '../../../interfaces/section';
import { SectionService } from 'app/services/section.service';

@Component({
    selector: 'select-section',
    templateUrl: './select-section.component.html',
    encapsulation: ViewEncapsulation.None
})
export class SelectSectionComponent implements OnInit, AfterViewInit{
    eventId: string;
    sectionList: Section[] = [];
    constructor(private activatedroute: ActivatedRoute,
                private _router: Router,
                private _sectionService: SectionService) {
        this.eventId = this.activatedroute.snapshot.paramMap.get('id');
    }
    ngOnInit() {
    }
    ngAfterViewInit() {
        this.getSectionDetails();
    }
    getSectionDetails() {
        this._sectionService
            .getSectionDetails(this.eventId)
            .subscribe((sectionList: Section[]) => {
                this.sectionList = sectionList;
                console.log(this.sectionList);
            });
    }
}

标签: angulartypescript

解决方案


推荐阅读