androidx.hilt.navigation.fragment
Kotlin
|Java
Extension functions summary
For Fragment | |
Lazy<VM> |
Fragment.hiltNavGraphViewModels(@IdRes : Int) Returns a property delegate to access a HiltViewModel-annotated ViewModel scoped to a navigation graph present on the {@link NavController} back stack: |
Extension functions
hiltNavGraphViewModels
@MainThread inline fun <reified VM : ViewModel> Fragment.hiltNavGraphViewModels(@IdRes : Int): Lazy<VM>
Returns a property delegate to access a HiltViewModel-annotated ViewModel scoped to a navigation graph present on the {@link NavController} back stack:
class MyFragment : Fragment() { val viewmodel: MainViewModel by androidx.hilt.navigation.fragment.hiltNavGraphViewModels(R.navigation.main) }
This property can be accessed only after this NavGraph is on the NavController back stack, and an attempt access prior to that will result in an IllegalArgumentException.
Parameters | |
---|---|
: Int | ID of a NavGraph that exists on the {@link NavController} back stack |