Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 53bef98

Browse files
committed
fixup
1 parent 275b4e3 commit 53bef98

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

docs/content/guide/compiler.ngdoc

+6-10
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ Double compilation occurs when an already compiled part of the DOM gets compiled
386386
undesired effect and can lead to misbehaving directives, performance issues, and memory
387387
leaks.
388388
A common scenario where this happens is a directive that calls `$compile` in a directive link
389-
function on the directive element. In the following example, a directive adds a mouseover behavior
389+
function on the directive element. In the following **faulty example**, a directive adds a mouseover behavior
390390
to a button with `ngClick` on it:
391391

392392
```
@@ -423,11 +423,10 @@ angular.module('app').directive('addMouseover', function($compile) {
423423
return {
424424
link: function(scope, element, attrs) {
425425
var newEl = angular.element('<span ng-show="showHint"> My Hint</span>');
426-
element.on('mouseenter mouseout', function() {
426+
element.on('mouseenter mouseleave', function() {
427427
scope.$apply('showHint = !showHint');
428428
});
429429

430-
attrs.$set('addMouseover', null);
431430
element.append(newEl);
432431
$compile(newEl)(scope); // Only compile the new element
433432
}
@@ -436,7 +435,7 @@ angular.module('app').directive('addMouseover', function($compile) {
436435
```
437436

438437
Another scenario is adding a directive programmatically to a compiled element and then executing
439-
compile again.
438+
compile again. See the following **faulty example**:
440439

441440
```html
442441
<input ng-model="$ctrl.value" add-options>
@@ -459,19 +458,16 @@ In that case, it is necessary to intercept the *initial* compilation of the elem
459458
1. Give your directive the `terminal` property and a higher priority than directives
460459
that should not be compiled twice. In the example, the compiler will only compile directives
461460
which have a priority of 100 or higher.
462-
2. Inside this directive's compile function, remove the original directive attribute from the element,
463-
and add any other directive attributes. Removing the attribute is necessary, because otherwise the
464-
compilation would result in an infinite loop.
465-
3. Compile the element but restrict the maximum priority, so that any already compiled directives
466-
are not compiled twice.
461+
2. Inside this directive's compile function, add any other directive attributes to the template.
462+
3. Compile the element, but restrict the maximum priority, so that any already compiled directives
463+
(including the `addOptions` directive) are not compiled again.
467464
4. In the link function, link the compiled element with the element's scope
468465

469466
```
470467
angular.module('app').directive('addOptions', function($compile) {
471468
return {
472469
priority: 100, // ngModel has priority 1
473470
terminal: true,
474-
template: '<input ng-model="$ctrl.value">',
475471
compile: function(templateElement, templateAttributes) {
476472
templateAttributes.$set('ngModelOptions', '{debounce: 1000}');
477473

0 commit comments

Comments
 (0)