Доступ к служебным переменным In Subscribe as Component Variables Angular7 / NGRX - PullRequest
0 голосов
/ 16 ноября 2018

У меня есть компонент, который импортирует сервис. Компонент вызывает метод класса обслуживания. Внутри этого метода есть переменные, которые присваиваются / дополняются. Я хочу, чтобы они были привязаны к переменным компонента. Подписка работает как задумано. Как ты это делаешь? Это единственный способ сделать это, используя что-то вроде этого:

@Output() change: EventEmitter < boolean > = new EventEmitter();

toggle() {
  this.isOpen = !this.isOpen;
  this.change.emit(this.isOpen);
}

и чем подписаться на это в компоненте.

Component.ts - сокращенный пример.

import { GridBuilderService } from '../../shared/services/grid.service';

export class MeetingStatusReportComponent implements OnInit, OnDestroy {
  communicationService,
  criteria: blahahah;
  resizeGrid: blahahah;
  gridOptions: blahahah;
  loadingDisable: blahahah;
  totalRecords: blahahah;

  constructor(
    public gridBuilder: GridBuilderService
  ) {}

  ...

  this.gridBuilder.subscribeForChanges(
    this.communicationService,
    this.criteria,
    this.resizeGrid,
    this.gridOptions,
    this.loadingDisable,
    this.totalRecords,
    params
  );
}

gridService.ts - сокращенный пример

import { Injectable } from '@angular/core';

@Injectable()
export class GridBuilderService {

  subscribeForChanges(
    communicationService, 
    criteria, 
    resizeGrid, 
    gridOptions, 
    loadingDisable, 
    totalRecords, 
    params
  ) {
    return communicationService.getMeetingStatusReportData(criteria)
    .subscribe(result => {
      let lastRow = result.meetings.totalRecords;
      resizeGrid();
      gridOptions.api.hideOverlay();
      loadingDisable = false; // want to set the this.loadingDisable on the component or carry it over somehow to assign.
      if (result.meetings.totalRecords === 0) {
        this.gridOptions.api.showNoRowsOverlay();
      }
      totalRecords = lastRow;
      // call the success callback
      params.successCallback(result.meetings.results, lastRow);
    });
  }
}
...