如何在AppModule中注册CompanyEffects,从服务器收到AppConfigService响应后。
在AppModule中注册效果
EffectsModule.forRoot([CompanyEffects]),
公司效应
export class CompanyEffects {
constructor(
private actions$: Actions,
private companyService: CompanyService,
private env: AppConfigService,
) {
}
}
@Effect()
loadTeams$: Observable<any> = this.actions$.pipe(
ofType(companyActions.CompanyActionsTypes.ALL_TEAMS_REQUEST),
mergeMap(() =>
this.companyService.teamList().pipe(
...
)
));
AppConfigService
export class AppConfigService {
public appConfig: AppConfig;
constructor(private injector: Injector) { }
loadAppConfig(): Promise<any> {
const http = this.injector.get(HttpClient);
let configUrl = "/api/data/config";
const promise = http
.get(configUrl)
.toPromise()
.then((data: AppConfig) => {
this.appConfig = data;
return data;
});
return promise;
}
}
没有办法。
你只能更新 CompanyEffects
跳过延迟动作,直到 this.env.appConfig
一直存在。