Pass parameter to viewmodel
See original GitHub issueHi, It is actually dagger 2.10 specific question. But I think no problem to ask here. My question is, what if you want to pass RepoView to your RepoViewModel? In my case I am using ViewModel. I am not using LiveData to observe. So I need to pass RepoView to RepoViewModel as parameter.
@Inject
public RepoViewModel(RepoRepository repository, RepoView repoView)
@Module
public class RepoModule {
@Provides
RepoView provideRepoView(RepoFragment repoFragment){
return repoFragment;
}
}
@ContributesAndroidInjector(modules = RepoModule.class)
abstract RepoFragment contributeRepoFragment();
I implemented it in this way but it gives me error compile time. It says that I didn’t provide RepoView to inject RepoViewModel.
RepoView can not bi provided without @Provides-annotation method.
Am I missing something? @JoseAlcerreca @yigit
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Android ViewModel additional arguments - Stack Overflow
So I don't know how to pass additional argument String param into my custom ViewModel . I can only pass Application context, but...
Read more >Advanced ViewModels (part I): Dependencies and Passing ...
This post focuses on which are the dependencies we will need and how to pass parameters to our ViewModel. Other posts in this...
Read more >How to add additional parameters to ViewModel via Kotlin
If you want to make it takes parameters, you need to make a new FactoryClass for each view model. But with Kotlin, it...
Read more >Parameter Injection for Android ViewModels
We can see in the following setup, Compose Navigation only allows us to pass parameters as part of the navigation route String.
Read more >Xamarin Passing parameters directly to ViewModel
would like to pass an Assignment_Id which is of type Guid to AssignmentViewModel. How do I do that? If you want to transfer...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Don’t pass your view (fragment) to your ViewModel, that’s rule number one of ViewModels 😃 This avoids leaks.
See https://developer.android.com/topic/libraries/architecture/viewmodel.html
You should not pass a callback to your ViewModel. If the View is retained, the callback (assuming it references back to the views) will be obsolete.
Instead, your ViewModel can provide observable action events on which your UI can react.