我正在尝试在https://ngrx.io/guide/data/上查找文档,以了解是否可以将 defaultDataService 扩展到https://ngrx.io/guide/data/entity-dataservice中提到的内容之外
期望的结果
car
我想要的是为我和plane
实体有不同的终点
const entityMetadata: EntityMetadataMap = {
car: {},
plane: {},
};
我知道可以通过以下方式自定义根目录。https://ngrx.io/guide/data/entity-dataservice#configure-the-defaultdataservice
但这并不能使每个实体都有自己的终点。
const defaultDataServiceConfig: DefaultDataServiceConfig = {
root: 'https://my-api-domain.com:8000/api/v1',
timeout: 3000, // request timeout
}
我的transport.services.ts
文件看起来像这样
import { Injectable } from '@angular/core';
import {
EntityCollectionServiceBase,
EntityCollectionServiceElementsFactory,
} from '@ngrx/data';
import { Mode } from '../models/mode.model';
@Injectable({ providedIn: 'root' })
export class CarService extends EntityCollectionServiceBase<Mode> {
constructor(serviceElementsFactory: EntityCollectionServiceElementsFactory) {
super('car', serviceElementsFactory);
}
}
@Injectable({ providedIn: 'root' })
export class PlaneService extends EntityCollectionServiceBase<Mode> {
constructor(serviceElementsFactory: EntityCollectionServiceElementsFactory) {
super('plane', serviceElementsFactory);
}
}
可能的解决方案
- 我看到这篇文章https://slides.com/jiali/deck-5#/34执行了以下操作,看起来像我所追求的,但找不到任何文档。
// create a customize http url generator
@Injectable({providedIn: 'root'})
export class CustomizeHttpUrlGenerator extends DefaultHttpUrlGenerator {
protected getResourceUrls(
entityName: string,
root: string
): HttpResourceUrls {
const urls = super.getResourceUrls(entityName, root);
urls.entityResourceUrl = urls.collectionResourceUrl;
return urls;
}
}
// app.module.ts, then register to providers
{
provide: HttpUrlGenerator,
useClass: CustomizeHttpUrlGenerator
}
任何帮助 - 非常感谢