injectViewModels

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

Deprecated

Renamed to lazyActivityViewModels.

Replace with

this.lazyViewModels(qualifier, ownerProducer, extrasProducer)

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

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

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.