<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tiago Miguel Costa Rodrigues</title>
    <description>The latest articles on DEV Community by Tiago Miguel Costa Rodrigues (@tmcrs123).</description>
    <link>https://dev.to/tmcrs123</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1017282%2F72be7b16-8582-4542-bb70-fdaecbd3f10c.jpeg</url>
      <title>DEV Community: Tiago Miguel Costa Rodrigues</title>
      <link>https://dev.to/tmcrs123</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tmcrs123"/>
    <language>en</language>
    <item>
      <title>Explaining Angular concepts to grandma 👵 - ViewRef / View ContainerRef</title>
      <dc:creator>Tiago Miguel Costa Rodrigues</dc:creator>
      <pubDate>Sat, 01 Mar 2025 00:04:43 +0000</pubDate>
      <link>https://dev.to/tmcrs123/explaining-angular-concepts-to-grandma-viewref-view-containerref-2lo8</link>
      <guid>https://dev.to/tmcrs123/explaining-angular-concepts-to-grandma-viewref-view-containerref-2lo8</guid>
      <description>&lt;p&gt;&lt;em&gt;Prologue: If you're looking for a deep technical breakdown, this isn't the place. My goal is to explain things in a way that even my grandmother could grasp—at least a little. This post reflects my personal understanding and mental model of the topic, intentionally keeping things non-technical as much as I can. That said, I strive for accuracy, so if I’ve got something wrong, I encourage you to correct me in the comments, and I’ll update the post. Learning is, after all, a collaborative process 🚀&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;One of the things that required a bit of digging for me to grasp is the concept of &lt;code&gt;ViewRef&lt;/code&gt; and &lt;code&gt;ViewContainerRef&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Sure, it sounds straightforward on the surface: a &lt;code&gt;ViewRef&lt;/code&gt; is obviously a reference to a view, a &lt;code&gt;ViewContainerRef&lt;/code&gt; is a reference to a view container.&lt;/p&gt;

&lt;p&gt;But what really is a view?&lt;/p&gt;

&lt;p&gt;According to the Angular documentation, a view is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The smallest unit of the UI that represents a portion of the screen rendered.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, in my mind, I ask myself:&lt;/p&gt;

&lt;p&gt;"Okay, so... if I have a simple &lt;code&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/code&gt; element, is that a view?"&lt;/p&gt;

&lt;p&gt;I mean, it checks all the boxes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It's a "unit of the UI" ✅&lt;/li&gt;
&lt;li&gt;That "represents a portion of the screen rendered" ✅&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, this is not the case. A &lt;code&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/code&gt; element is not a view. Why?&lt;/p&gt;

&lt;h2&gt;
  
  
  What makes a view a "view"? 🤔
&lt;/h2&gt;

&lt;p&gt;Think about the example above: if you had a component with a hundred &lt;code&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/code&gt; elements, and each one of those &lt;code&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/code&gt; elements created a view, you would have 100 views. That sure sounds like a lot to manage, even for a computer.&lt;/p&gt;

&lt;p&gt;As such, in my opinion, saying a view is &lt;em&gt;"The smallest unit of the UI that represents a portion of the screen rendered"&lt;/em&gt; is misleading.&lt;/p&gt;

&lt;p&gt;I think a better way of describing a view is: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Any bit of your template that can change&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  What do you mean by "change"? 🔁
&lt;/h3&gt;

&lt;p&gt;Consider this simple component that represents a list of fruits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app-fruit-list&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;templateUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./fruit-list.component.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FruitListComponent&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- fruit-list.component.html --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Apples&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Bananas&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Pears&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The HTML markup above is &lt;em&gt;static&lt;/em&gt;. There's no Angular stuff there that can either add or delete a list item or hide the list altogether. You are stuck eating apples, bananas and pears.&lt;/p&gt;

&lt;p&gt;Now imagine we change our component to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app-fruit-list&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;templateUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./fruit-list.component.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FruitListComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;fruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

  &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nx"&gt;fruitsService&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;inject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;FruitsService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


  &lt;span class="nf"&gt;ngOnInit&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fruitsService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetchFruits&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;*ngFor=&lt;/span&gt;&lt;span class="s"&gt;"let fruit of fruits"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;{{fruit}}&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now our list of fruits can have any number of items. Maybe our fruit supplier only has 10 different fruits available. Or maybe it has a million different fruits. Maybe in the morning apples are available but sold out in the afternoon. We don't know. And as it turns out Angular doesn't know either.&lt;/p&gt;

&lt;p&gt;Because Angular doesn't know how many fruits will exist, it needs to add or remove &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; elements dynamically.&lt;/p&gt;

&lt;p&gt;Therefore, Angular will now consider our list of fruits a 'view'—or, in 'grandma terms,' something that can change at any time.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: The example above uses &lt;code&gt;ngFor&lt;/code&gt;. However other things like &lt;code&gt;&amp;lt;ng-template&amp;gt;&lt;/code&gt; or &lt;code&gt;ngIf&lt;/code&gt; have the same power to create "views". If it makes the UI change dynamically, it creates a "view".&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A "view" inside the box 📦
&lt;/h2&gt;

&lt;p&gt;You'll notice that in the previous paragraph I always referred to the bit of HTML that can change dynamically as a "view". Notice the quotes here - &lt;em&gt;"view"&lt;/em&gt; - as they are absolutely critical.&lt;/p&gt;

&lt;p&gt;When you tell Angular something will have to be updated dynamically, Angular under the hood wraps that HTML element in a &lt;code&gt;ViewContainerRef&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The way I think about &lt;code&gt;ViewContainerRef&lt;/code&gt; is &lt;em&gt;"a box where things are can be added, removed or moved around"&lt;/em&gt;. What "things", you ask ? More on that in a second. &lt;/p&gt;

&lt;p&gt;For now let's focus on counting how many "boxes" /&lt;code&gt;ViewContainerRef&lt;/code&gt;s we have and where they come from.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Optional side note: open your editor and navigate to the &lt;code&gt;ViewContainerRef&lt;/code&gt; class definition. Have a look at the methods there. You will see stuff like &lt;code&gt;CreateComponent&lt;/code&gt;, &lt;code&gt;CreateEmbeddedView&lt;/code&gt;, &lt;code&gt;get&lt;/code&gt;, &lt;code&gt;move&lt;/code&gt; or &lt;code&gt;remove&lt;/code&gt;. That looks a lot like adding or removing things from a box, if you ask me.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Stacking up the boxes 📦📦
&lt;/h2&gt;

&lt;p&gt;Every time Angular creates a component, you get &lt;em&gt;at least one&lt;/em&gt; box / &lt;code&gt;ViewContainerRef&lt;/code&gt;. This will be the &lt;code&gt;ViewContainerRef&lt;/code&gt; for the &lt;em&gt;whole&lt;/em&gt; of your component. Let's go back to our list of fruits component and draw some boxes and arrows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F189u6ukfs0w5882hzyes.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F189u6ukfs0w5882hzyes.png" alt="The top level ViewContainerRef is a " width="800" height="334"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The top level ViewContainerRef is a "box" that holds all of the Fruit List component HTML&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Notice I said &lt;em&gt;"at least"&lt;/em&gt; one &lt;code&gt;ViewContainerRef&lt;/code&gt;. Why? Because if you add things to your template that change dynamically, then you can have many &lt;code&gt;ViewContainerRef&lt;/code&gt;s. In fact, in this example we have 2 &lt;code&gt;ViewContainerRef&lt;/code&gt;s: the top level one and the one generated by the &lt;code&gt;ngIf&lt;/code&gt; in the &lt;code&gt;ul&lt;/code&gt; element. If we draw more boxes and arrows, it looks like this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flanxlm50u0mw577oebme.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flanxlm50u0mw577oebme.png" alt="Another ViewContainerRef that was there all along" width="800" height="334"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Another ViewContainerRef that was there all along&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Putting things in the box 📦 ⬅
&lt;/h2&gt;

&lt;p&gt;Now that we have a clue of what a &lt;code&gt;ViewContainerRef&lt;/code&gt; is and roughly what it does, let's talk about &lt;code&gt;ViewRef&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;According to the Angular documentation a &lt;code&gt;ViewRef&lt;/code&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Represents an Angular view&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That sounds reasonable and straightforward enough. Upon reading this, I immediately jumped to the following (wrong) conclusion:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;code&gt;ViewRef&lt;/code&gt; is the bit of HTML inside of the &lt;code&gt;ViewContainerRef&lt;/code&gt;. So there must be a way for me to retrieve it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;With this in mind, I tried a few things—ranging from utterly stupid to moderately stupid—but alas, to no avail.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// this is stupid, ViewRef is not even injectable 🙃&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;viewReference&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;inject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ViewRef&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;viewReference&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;viewContainerRef&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;looking for something here that returns the viewRef but such thing doesn't exist&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So where is this &lt;code&gt;ViewRef&lt;/code&gt; that "represents an Angular view"? I can't seem to find it anywhere!&lt;/p&gt;

&lt;p&gt;As it turns out, there are three very important words that, I think, were left out of that definition, and they make a big difference:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Represents an Angular view &lt;em&gt;you create yourself&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A &lt;code&gt;ViewRef&lt;/code&gt; is not something that exists in the box /&lt;code&gt;ViewContainerRef&lt;/code&gt;, it is what you get when you &lt;em&gt;put&lt;/em&gt; something in the box. It's a reference pointing to the view you just created.&lt;/p&gt;

&lt;h2&gt;
  
  
  The ViewRef at the bottom of the box 🎁
&lt;/h2&gt;

&lt;p&gt;As we have discussed before a &lt;code&gt;ViewContainerRef&lt;/code&gt; is capable, among other things, of creating components dynamically (or in our grandma terms "putting things in the box").&lt;/p&gt;

&lt;p&gt;There are a couple of methods in a &lt;code&gt;ViewContainerRef&lt;/code&gt; that allow us to do that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// class stuff&lt;/span&gt;
      &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nx"&gt;myViewContainerRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;inject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ViewContainerRef&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//more class stuff&lt;/span&gt;

    &lt;span class="nf"&gt;someMethod&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;aReferenceToAComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;myViewContainerRef&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;createComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;SimpleComponent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//is of type ComponentRef&amp;lt;SimpleComponent&amp;gt;&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;aReferenceToAnEmbeddedView&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;myViewContainerRef&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;createEmbeddedView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;someTemplate&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;//is of type EmbeddedViewRef&amp;lt;any&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will notice that none of those 2 methods returns a &lt;code&gt;ViewRef&lt;/code&gt;. How come? We should have a &lt;code&gt;ViewRef&lt;/code&gt; right? If I just put something in the box I want a reference to it.&lt;/p&gt;

&lt;p&gt;Take a deep breath; don't sweat it. It is there—just a bit hidden.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ComponentRef&lt;/code&gt; has a &lt;code&gt;hostView&lt;/code&gt; property. And that &lt;code&gt;hostView&lt;/code&gt; property is, in fact, a &lt;code&gt;ViewRef&lt;/code&gt;. So there's one ✅&lt;/p&gt;

&lt;p&gt;&lt;code&gt;EmbeddedViewRef&lt;/code&gt; extends from &lt;code&gt;ViewRef&lt;/code&gt;, so it is, in fact, a &lt;code&gt;ViewRef&lt;/code&gt;. So there's two ✅&lt;/p&gt;

&lt;p&gt;We have found our &lt;code&gt;ViewRef&lt;/code&gt;s 🎉&lt;/p&gt;

&lt;p&gt;You will notice that you can do a lot less with &lt;code&gt;ViewRef&lt;/code&gt; when compared with &lt;code&gt;ViewContainerRef&lt;/code&gt;. With &lt;code&gt;ViewRef&lt;/code&gt; you can do stuff that relates to a view (like marking it for change detection or destroy it), whereas with &lt;code&gt;ViewContainerRef&lt;/code&gt; you can do stuff that relates to the place where the view lives (like adding new components or moving existing components around).&lt;/p&gt;

&lt;h1&gt;
  
  
  Wrapping it up
&lt;/h1&gt;

&lt;p&gt;Hopefully all of these non-sense with boxes and fruits helps you understand the difference between &lt;code&gt;ViewRef&lt;/code&gt; and &lt;code&gt;ViewContainerRef&lt;/code&gt;. If you just remember one thing from this post remember the following:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;One is the box; the other is what you get when you put something in the box&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>angular</category>
      <category>typescript</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
