How do I wait for a response from the server?

  • 0
    There is a class with DI dependencies:

    export class DocumentsSettings implements Settings {
            public filtersRepository: DocumentsFiltersRepository,
            public sortingRepository: DocumentsSortingRepository,
            private http: HttpClient,
        ) {
        private load(): void {
                .pipe(map((response: string) => JSON.parse(response)))
                .subscribe((response: ResponseSettings) => {

    The problem is that the `load ()` method returns data asynchronously faster than in the class: DocumentsFiltersRepository

    export class DocumentsFiltersRepository extends FiltersRepository {
        constructor(private documentsReferencies: DocumentsReferencies) {
            this.reestrTypes.subscribe((collection: any[]) => {
                    new Filter({
                        title: 'По статусу',
                        type: FilterType.DocumentsStatus,
                        collection: documentsStatusList,
                    new Filter({
                        title: 'Реестр',
                        type: FilterType.DocumentsReestr,
                        collection: collection,
        public get reestrTypes(): Observable<any> {
            return this.documentsReferencies.reestrtypes;

    I need to make sure that before calling the method: this.filtersRepository.modifyDefault (); , the method, depending on the dependency, would have already worked and returned the data:

    this.reestrTypes.subscribe((collection: any[]) => {}

    How to achieve this?
    JavaScript Anonymous, May 11, 2019

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!