我有一个正在导入服务的组件。组件调用服务类上的方法。该方法内部是分配/增强的变量。我希望将它们绑定到组件变量。订阅正在按预期工作。你怎么做到这一点?这是通过使用类似这样的操作的唯一方法:
@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);
});
}
}