how to get viewModel by viewModels? (fragment-ktx) : <p>I am working with Single viewModel for the Activity and all of it's fragment.</p>

<p>So to initialise <code>viewmodel</code> if have to write this setup code in <code>onActivityCreated</code> of all the fragment's</p>

<pre><code>    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        viewModel = ViewModelProviders.of(activity!!).get(NoteViewModel::class.java)
    }
</code></pre>

<p>I was going thorough the Android KTX extension page:(<a href="https://developer.android.com/kotlin/ktx#fragment" rel="noreferrer">refer here</a>) </p>

<p>and i found i can initialise view model like this:</p>

<pre><code>    // Get a reference to the ViewModel scoped to this Fragment
    val viewModel by viewModels&lt;MyViewModel&gt;()

    // Get a reference to the ViewModel scoped to its Activity
    val viewModel by activityViewModels&lt;MyViewModel&gt;()
</code></pre>

<p>So I added below dependency's to my gradle(app):</p>

<pre><code>    //ktx android
    implementation 'androidx.core:core-ktx:1.0.2'
    implementation 'androidx.fragment:fragment-ktx:1.0.0'
    implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
</code></pre>

<p>But when i try to use <code>viewModels/activityViewModels</code> in my application their reference in not found.</p>

<p>I want help in how to use these extension's with some basic example i tried searching for examples haven't found any.</p>
