modular icon indicating copy to clipboard operation
modular copied to clipboard

async bind not called after module disposed

Open komangnopha opened this issue 5 years ago • 4 comments

i've injecting async bind to certain module, when the module first initialized it called async bind. but when module got disposed and initialized again, it didnt call async bind method again. is there any ways to called the async bind method when module got initialized every time ? thanks

komangnopha avatar Aug 02 '21 13:08 komangnopha

Hi! @komangnopha , can you provide a small POC?

raphaelbarbosaqwerty avatar Aug 02 '21 23:08 raphaelbarbosaqwerty

thx for your response @raphaelbarbosaqwerty

here is my module that injecting asyncBind method image

here my method that injected with asyncBind image take a look i've added debug code there

i've added await isModuleReady in my guard image

in the first initialization, injected bind is called when module was initialized image

but after module disposed, and then initialize again, the injected bind not called again image

is there anything wrong in my code ? thx before

komangnopha avatar Aug 03 '21 02:08 komangnopha

Hey! In fact this is normal behavior. The resolution of an AsyncBind is done only once, as it is expected that a Bind will exit from there. If you need to run it every time, try Modular.getAsync() instead.

Another detail. AsyncBind generates a Bind with the Future's return, so if it's returning a bool, it will create a Bind.

Hope this helps/

jacobaraujo7 avatar Aug 03 '21 14:08 jacobaraujo7

thanks @jacobaraujo7 for your answer. i thought i can using AsyncBind everytime before initialize one module, in my case, i need AsyncBind to ensure that one method in controller A is called before initialize module A, and then when entering another module i can use data provided by controller A without called it everytime using modular.getAsync.

FYI i'm using router outlet, and i was mention about root module (module A) that contain another module as children

komangnopha avatar Aug 03 '21 15:08 komangnopha