You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
$compile: "the root of the template always gets a new scope..." What is it about? #15109
The scope property can be true, an object or a falsy value: ...
true: A new child scope that prototypically inherits from its parent will be created for the directive's element. If multiple directives on the same element request a new scope, only one new scope is created. The new scope rule does not apply for the root of the template since the root of the template always gets a new scope.
I can't understand the last sentence. Does it mean that even if you set scope to false in the DDO, your directive will create a new scope if it has a template? Then, it's not true: see this plunk. Does this sentence mean something different?
I think this is a relic of the past and it basically refers to the root element of the application (which gets attached to $rootScope automatically.
It was introduced back in 4804c83 (v1.0.0-rc.2). At that time, it seems that the HTML inside index.html was referred to as "the angular template" or "DOM template" or just "template".
A few quotes from the (then) docs:
About compilation:
At application compile time, a root scope is created and is attached to the root <HTML> DOM element.
During the compilation phase, the compiler matches directives against the DOM template. The directives usually fall into one of two categories:
Observing directives, such as double-curly expressions {{expression}}, register listeners using the $watch() method. This type of directive needs to be notified whenever the expression changes so that it can update the view.
Listener directives, such as ng:click, register a listener with the DOM. When the DOM listener fires, the directive executes the associated expression and updates the view using the $apply() method.
About templates:
The following code snippet shows a simple angular template made up of standard HTML tags along with angular directives, markup, and expressions:
<html ng:app>
<!-- Body tag augmented with ng:controller directive -->
<body ng:controller="MyController">
<input ng:model="foo" value="bar">
<!-- Button tag with ng:click directive, and string expression 'buttonText'
wrapped in "{{ }}" markup -->
<button ng:click="changeFoo()">{{buttonText}}</button>
<script src="angular.js">
</body>
</html>
In a simple single-page app, the template consists of HTML, CSS, and angular directives contained in just one HTML file (usually index.html). In a more complex app, you can display multiple views within one main page using "partials", which are segments of template located in separate HTML files.
Iff my analysis is correct, we can get rid of that sentence altogether as it is confusing (and doesn't seem related to directives anyway).
But I am just guessing here - there is always a chance it means something else...
Activity
gkalpak commentedon Sep 8, 2016
I think this is a relic of the past and it basically refers to the root element of the application (which gets attached to
$rootScopeautomatically.It was introduced back in 4804c83 (v1.0.0-rc.2). At that time, it seems that the HTML inside
index.htmlwas referred to as "the angular template" or "DOM template" or just "template".A few quotes from the (then) docs:
About compilation:
About templates:
Iff my analysis is correct, we can get rid of that sentence altogether as it is confusing (and doesn't seem related to directives anyway).
But I am just guessing here - there is always a chance it means something else...
Narretz commentedon Sep 9, 2016
I think we can remove it, as it doesn't really make anything clearer.
docs($compile): remove meaningless sentence
docs($compile): remove meaningless sentence
docs($compile): remove obsolete sentence
docs($compile): remove obsolete sentence
docs($compile): remove obsolete sentence
docs($compile): remove obsolete sentence
docs($compile): remove obsolete sentence
docs($compile): remove obsolete sentence
docs($compile): remove obsolete sentence
docs($compile): remove obsolete sentence
docs($compile): remove obsolete sentence