<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pro-Tek Blog &#187; Scope Inheritance</title>
	<atom:link href="http://www.pro-tekconsulting.com/blog/tag/scope-inheritance/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pro-tekconsulting.com/blog</link>
	<description>For UI developers / UI designers and UI trends</description>
	<lastBuildDate>Thu, 05 Sep 2019 03:59:47 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.34</generator>
	<item>
		<title>Scope Inheritance  in Angular JS</title>
		<link>http://www.pro-tekconsulting.com/blog/scope-inheritance-in-angular-js/</link>
		<comments>http://www.pro-tekconsulting.com/blog/scope-inheritance-in-angular-js/#comments</comments>
		<pubDate>Fri, 10 Apr 2015 04:19:03 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[AngularJS]]></category>
		<category><![CDATA[Scope Inheritance]]></category>

		<guid isPermaLink="false">http://www.pro-tekconsulting.com/blog/?p=443</guid>
		<description><![CDATA[<p>Scope Inheritance in Angular JS In Angular, a scope is associated to an element, while an element is not necessarily directly associated with a scope. It is important to have a solid understanding of prototypical inheritance and differentiate the types of scopes. A child scope normally (prototypically) inherits from its parent scope, but not always. [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://www.pro-tekconsulting.com/blog/scope-inheritance-in-angular-js/">Scope Inheritance  in Angular JS</a> appeared first on <a rel="nofollow" href="http://www.pro-tekconsulting.com/blog">Pro-Tek Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h4>Scope Inheritance  in Angular JS</h4>
<p style="text-align: justify;">In Angular, a scope is associated to an element, while an element is not necessarily directly associated with a scope. It is important to have a solid understanding of prototypical inheritance and differentiate the types of scopes. A child scope normally (prototypically) inherits from its parent scope, but not always. Scope inheritance is also normally straightforward, until 2-way data binding is required (i.e., ng- model) in the child scope. In that case, the child scope gets its own property that hides/shadows the parent property of the same name.</p>
<p style="text-align: justify;">There are four types of scopes. The first one has &#8220;normal prototypical scope inheritance&#8221;; ng- include, ng-switch, ng-controller &#8211; create new scopes and inherit prototypically ( note that, ng- controller, however, is considered bad form for two controllers to share information via &#8220;scope inheritance.&#8221;), directive with scope: true. If more than one directive (on the same DOM element) requests a new scope, only one new child scope is created. Since we have &#8220;normal&#8221; prototypal inheritance, you want to be wary of 2-way data binding to parent scope primitives, and child scope hiding/shadowing of parent scope properties.</p>
<p style="text-align: justify;">The second type has &#8220;normal prototypal scope inheritance with a cop y/assignment&#8221; &#8211; ng-repeat. Each item/ iteration of ng-repeat creates a new child scope, and that new child scope always gets a new property. Changing the child scope property&#8217;s value does not change the array the parent scope references.</p>
<p style="text-align: justify;">The third type of scope and the one exception to the rule of inheritance is an &#8220;isolate scope” (created by directive with scope: {&#8230;}. Note, also, that, by default, directives do not create new scopes i.e., the default is scope: false so there is no inheritance there. Default is not a good choice for writing directives that are intended as reusable components.) An &#8220;isolate scope&#8221; is not prototypical but &#8216;=&#8217;, &#8216;@&#8217;, and &#8216;&amp;&#8217; provide a mechanism to access parent scope properties, via attributes. The object hash is used to set up two-way binding (using &#8216;=&#8217;) or one-way binding (using &#8216;@&#8217;) between the parent scope and the isolate scope. There is also &#8216;&amp;&#8217; to bind to parent scope expressions. So, these all create local scope properties that are derived from the parent scope. This construct is often the best choice when creating a &#8220;reusable component&#8221; directive, since the directive cannot accidentally read or modify the parent scope.</p>
<p><img class="aligncenter" src="http://www.pro-tekconsulting.com/blog/wp-content/uploads/2015/04/scope-inheritance-angular-js.png" alt="Scope Inheritance in Angular JS" width="469" height="132" /></p>
<p style="text-align: justify;">The last type is a &#8220;transcluded scope&#8221;- directive with transclude: true. The directive creates a new &#8220;transcluded&#8221; child scope, which prototypically inherits from the parent scope. The transcluded and the isolated scope are siblings &#8211; the $parent property of each scope references the same parent scope.</p>
<p style="text-align: justify;">It&#8217;s important to remember that for all scopes (prototypal or not), Angular always tracks a parent- child relationship (i.e., a hierarchy), via properties $parent and $$ childHead and $$childTail.</p>
<p style="text-align: justify;">In the case of a more complex scope inheritance, your workarounds should include three basic steps: 1) define objects in the parent for your mode, then reference a property of that object in the child: parentObj.someProp, 2) use $parent.parentScopeP roperty (where possible), and 3) define a function on the parent scope, and call it from the child.</p>
<p>The post <a rel="nofollow" href="http://www.pro-tekconsulting.com/blog/scope-inheritance-in-angular-js/">Scope Inheritance  in Angular JS</a> appeared first on <a rel="nofollow" href="http://www.pro-tekconsulting.com/blog">Pro-Tek Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pro-tekconsulting.com/blog/scope-inheritance-in-angular-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
