Hi guys, we are facing an issue when we register ngrx effect with injected service (generateg using nswag). when we register effect into root module angular throws exception because abp config is not yet loaded properly because app_initializer is not probably yet finished or effect is registered earlier we can not find a way how to obtain this issue unfortunately. We are quite new in angular.
Do you have any advices pleaee thanks.
we are using latest aspnetzero web api & angular 8 template.
thanks a lot.
13 Answer(s)
-
0
Hi @demirmusa, Sorry for delayed answer. We had lot of work before holidays. I have created a sample for you NgrxSample It was uploaded to our czech sharing website - you can downlaod it using slow download without creating an account. When you will have problem to download the file just tell me I will upload it elsewhere. Steps to simulate:
- In Visual studio open NgrxSampleDemo.Web.sln
- Run Update-Database command in Nuget Package Manager console
- Run NgrxSampleDemo WebAPI
- Open NgrxSampleDemo angular app
- Run angular app (npm i, npm start)
- Login page does not show up and in Developer tools (Ctrl+Shift+I or F12 key) console you can see an error
- When you comment out line 322 in root.module.ts everything works OK (except dispatching data to ngrx state of course)
Just to mention when we register Effect into lazy loaded module and register it as feature it works OK without any problem but we need to dispatch ngrx store in RootModule too.
Thansk for help.
-
0
Hi @ismcagdas, No I gave you link to sharing website and you answered me this month ago (just 4 comments above):
Hi @mhrabak
Thank you for sharing the project. I removed the download link since the urls in this website is public and everyone can download the source code. I downloaded the source code. I will check the problem and inform you if you haven't solved the project
-
0
I have just encounter this myself. Has any progress been made on this?
Cause The problem seems to be caused by the service proxy being initialized before the
API_BASE_URL
has been set. This seems to cause a knockon effect on any other service proxy injected into a constructor. In practice this leads to all proxy calls going to undesireable domains and that is why nothing loads because the endpoints are invalid.Source: service-proxies.ts:
export const API_BASE_URL = new InjectionToken<string>('API_BASE_URL');
Workaround I have found a workaround to this for now, but I don't know if this has severe side effects yet. On your ngRx Effect instead of injecting your service proxy in the constructor inject an Injector and for convenience use an accessor to keep your code the same.
I.e. Instead of
constructor(private actions$: Actions, private demoService: DemoServiceProxy) {}
use
get demoService(): DemoServiceProxy { const { injector } = this; return injector.get(DemoServiceProxy); } constructor(private actions$: Actions, private injector: Injector) {}