用NGRX注册效果

问题描述 投票:0回答:1

如何在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;
    }      
}
angular typescript ngrx ngrx-effects
1个回答
0
投票

没有办法。

你只能更新 CompanyEffects 跳过延迟动作,直到 this.env.appConfig 一直存在。

© www.soinside.com 2019 - 2024. All rights reserved.