Hi, I was wondering how to scope viewModel to its ...
# koin
a
Hi, I was wondering how to scope viewModel to its parent fragment? in previous version we could do something like:
val viewModel by sharedViewModel<SomeViewModel>(from = { parentFragment!! })
but the
from
seems to be removed in the current
2.1.5
version. Any reason why was it removed? and what to do instead?
a
isn’t something like this working
Copy code
requireParentFragment().sharedViewModel()
?
a
oh i see... that never occured to me... i will try.. thank you verymuch
a
basic idea is to get an instance from the parent fragment scope, not from the scope of the current fragment. I’m using same scenario with activity. But I remember it was working with parent fragment as well.
a
oh wait..
parentFragment.sharedViewModel()
still scopes the viewModel to the activity and not the parent fragment... maybe
parentFragment.viewModel()
instead?
a
yes, you might be right
a
Thank you very much ❤️ Big help 😄