Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your fiddles create three scopes:</p> <ol> <li>a scope associated with controller <code>Ctrl</code>, because of <code>ng-controller</code></li> <li>a directive transcluded scope, because of <code>transclude: true</code></li> <li>a directive isolate scope, because of <code>scope: { ... }</code></li> </ol> <p>In fiddle1, before we type anything into the text box we have the following:</p> <p><img src="https://i.stack.imgur.com/GeL6b.png" alt="enter image description here"></p> <p>Scope 003 is the scope associated with the controller. Since we didn't type into the textbox yet, there is no <code>data</code> property. In isolate scope 004, we see that a <code>title</code> property was created, but it is empty. It is empty because the parent scope doesn't have a <code>data.title</code> property yet.</p> <p>After typing <code>my title</code> into the textbox, we now have:</p> <p><img src="https://i.stack.imgur.com/kwtt2.png" alt="enter image description here"></p> <p>Controller scope 003 now has a new <code>data</code> object property (which is why it is colored yellow), which has a <code>title</code> property now set to <code>my title</code>. Since isolate scope property <code>title</code> is one-way databound to the interpolated value of <code>data.title</code>, it also gets the value <code>my title</code> (the value is colored yellow because it changed).</p> <p>The transcluded scope prototypically inherits from the controller scope, so inside the transcluded HTML, angular can follow the prototype chain and find <code>$scope.data.title</code> in the parent scope (but <code>$scope.title</code> doesn't exist there).</p> <p>The isolate scope only has access to its own properties, hence only property <code>title</code>.</p> <p>In fiddle2, before typing we have the same picture as in fiddle1.</p> <p>After typing <code>my title</code>:</p> <p><img src="https://i.stack.imgur.com/OGpJd.png" alt="enter image description here"></p> <p>Notice where the new <code>data.title</code> property showed up -- on the transcluded scope. The isolate scope is still looking for <code>data.title</code> on the controller scope, but its not there this time, so its <code>title</code> property value remains empty.</p> <p>In fiddle3, before typing we have the same picture as in fiddle1.</p> <p>After typing <code>my title</code>:</p> <p><img src="https://i.stack.imgur.com/00SS0.png" alt="enter image description here"></p> <p>Notice where the new <code>data.title</code> property showed up -- on the isolate scope. None of the other scopes have access to the isolate scope, so the string <code>my title</code> won't appear anywhere else.</p> <hr> <p><strong>Update for Angular v1.2:</strong></p> <p>With change <a href="https://github.com/angular/angular.js/commit/eed299a31b5a6dd0363133c5f9271bf33d090c94" rel="noreferrer">eed299a</a> Angular now clears the transclusion point before transcluding, so the <code>Template title: ...</code> and <code>Template data.title: ...</code> parts won't show up unless you modify the template such that <code>ng-transclude</code> is by itself, such as:</p> <pre><code>'&lt;h3&gt;Template title: &lt;span style="color:red"&gt;{{title}}&lt;/span&gt;&lt;/h3&gt;' + '&lt;h3&gt;Template data.title: &lt;span style="color:red"&gt;{{data.title}}&lt;/span&gt;&lt;/h3&gt;' + '&lt;div ng-transclude&gt;&lt;/div&gt;' </code></pre> <p>In the update below for Angular v1.3, this template change was made.</p> <hr> <p><strong>Update for Angular v1.3+:</strong></p> <p>Since Angular v1.3, the transcluded scope is now a child of the directive's isolate scope, rather than a child of the controller scope. So in fiddle1, before we type anything:</p> <p><img src="https://i.stack.imgur.com/hwgjb.png" alt="enter image description here"></p> <p>The pictures in this update are drawn with the <a href="https://github.com/mrajcok/angularjs-periscope" rel="noreferrer">Peri$scope</a> tool, so the pictures are a bit different. The <code>@</code> indicates we have an isolate scope property that uses the <code>@</code> syntax, and the pink background means that the tool was unable to find an ancestor reference for the mapping (which is true, since we didn't type anything in to the textbox yet).</p> <p>After typing <code>my title</code> into the textbox, we now have:</p> <p><img src="https://i.stack.imgur.com/vkXNP.png" alt="enter image description here"></p> <p>Isolate properties that use <code>@</code> binding will always show the interpolated string result in the isolate scope after the <code>@</code> symbol. Peri$scope was also able to find this exact string value in an ancestor scope, so it also shows a reference to that property.</p> <p>In fiddle 2, before typing we have the same picture as in fiddle1.</p> <p>After typing <code>my title</code>:</p> <p><img src="https://i.stack.imgur.com/gxRrx.png" alt="enter image description here"></p> <p>Notice where the new <code>data.title</code> property showed up -- on the transcluded scope. The isolate scope is still looking for <code>data.title</code> on the controller scope, but its not there this time, so its <code>title</code> property value remains empty.</p> <p>In fiddle3, before typing we have the same picture as in fiddle1.</p> <p>After typing <code>my title</code>:</p> <p><img src="https://i.stack.imgur.com/dpHZC.png" alt="enter image description here"></p> <p>Notice where the new <code>data.title</code> property showed up -- on the isolate scope. Even though the transcluded scope has access to the isolate scope via the <code>$parent</code> relationship, it won't look there for <code>title</code> or <code>data.title</code> -- it will only look in the controller scope (i.e., it will follow the prototypal inheritance), and the controller scope doesn't have these properties defined.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload