我正在尝试使用 ngrx/data -> saveEntities 将多个实体添加到商店。到目前为止,我得到了这个:
@Injectable()
export class MaintenanceEntityService extends EntityCollectionServiceBase<Maintenance> {
constructor(
private serviceElementsFactory: EntityCollectionServiceElementsFactory,
private entityCacheDispatcher: EntityCacheDispatcher) {
super('Maintenance', serviceElementsFactory);
}
addBatch(maintenances: Maintenance[]) {
const changes: ChangeSetItem[] = [
cif.add('Maintenance', maintenances)
];
const changeSet: ChangeSet = { changes, tag: 'Creating alert batch'};
return this.entityCacheDispatcher.saveEntities(changeSet, `${environment.API}maintenances`).pipe(
map(response => response)
);
}
}
我的端点接收并返回一个像这样的对象:
interface ChangeSet<T = any> {
changes: ChangeSetItem[]
extras?: T
tag?: string
}
在后端,我将所有实体插入数据库,然后在返回同一对象之前更新 id,但在 Angular 应用程序中,商店没有更新。我错过了什么吗?