解决了。
注册了一个扩展 DefaultDataService 的新数据服务
src/app/store/entity-store-module.ts
import {EntityDataService} from '@ngrx/data';
import {TestDataService} from './test-data-service';
import {NgModule} from '@angular/core';
@NgModule({
providers: [
TestDataService
]
})
export class EntityStoreModule {
constructor(
entityDataService: EntityDataService,
testDataService: TestDataService,
) {
entityDataService.registerService('User', testDataService);
}
}
src/app/store/test-data.service.ts
import {
DefaultDataService,
DefaultHttpUrlGenerator,
DefaultPluralizer, HttpMethods,
HttpUrlGenerator,
Logger,
} from '@ngrx/data';
import {Injectable} from '@angular/core';
import {User} from '../users/models/user.model';
import {HttpClient} from '@angular/common/http';
import {pluralNames} from './entity-metadata';
import {Observable} from 'rxjs';
@Injectable()
export class TestDataService extends DefaultDataService<User> {
constructor(
http: HttpClient,
httpUrlGenerator: HttpUrlGenerator,
logger: Logger
) {
logger.log(http, httpUrlGenerator);
const url = new DefaultHttpUrlGenerator(new DefaultPluralizer([pluralNames]));
url.registerHttpResourceUrls({Label: {entityResourceUrl: 'user', collectionResourceUrl: 'users'}});
super('User', http, url);
}
protected execute(method: HttpMethods, url: string, data?: any, options?: any): Observable<any> {
if (method === 'POST') {
url = 'client/' + 1 + '/user'; // where 1 will be replaced dynamically
}
return super.execute(method, url, data, options);
}
}