lazyViewModels

inline fun <VM : ViewModel> Fragment.lazyViewModels(qualifier: Any? = null, noinline ownerProducer: () -> ViewModelStoreOwner = { this }, noinline extrasProducer: () -> CreationExtras? = null): Lazy<VM>

Returns a Lazy delegate to access the Fragment's ViewModel provided by Koject

class TopFragment : Fragment() {
private val viewModel: TopViewModel by lazyViewModels()
}

Parameters

qualifier

Qualifier for identification.

ownerProducer

Specify ViewModelStoreOwner that controls the scope and lifetime of the returned ViewModel. The default is the current Fragment, which can be changed to ComponentActivity or parent Fragment.

extrasProducer

Create the default extras that will be used to create the ViewModel.