Skip to content

Commit c8c3de4

Browse files
authored
docs($compile): add known issues with replace:true
Closes angular#16523 Related angular#2573 Related angular#5695 Related angular#9837 Related angular#10612
1 parent 3a2aea7 commit c8c3de4

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

src/ng/compile.js

+57-3
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,10 @@
531531
* $sce#getTrustedResourceUrl $sce.getTrustedResourceUrl}.
532532
*
533533
*
534-
* #### `replace` (*DEPRECATED*)
535-
*
536-
* `replace` will be removed in next major release - i.e. v2.0).
534+
* #### `replace`
535+
* <div class="alert alert-danger">
536+
* **Note:** `replace` is deprecated in AngularJS and has been removed in the new Angular (v2+).
537+
* </div>
537538
*
538539
* Specifies what the template should replace. Defaults to `false`.
539540
*
@@ -983,6 +984,59 @@
983984
compiled again. This is an undesired effect and can lead to misbehaving directives, performance issues,
984985
and memory leaks. Refer to the Compiler Guide {@link guide/compiler#double-compilation-and-how-to-avoid-it
985986
section on double compilation} for an in-depth explanation and ways to avoid it.
987+
988+
* @knownIssue
989+
990+
### Issues with `replace: true`
991+
*
992+
* <div class="alert alert-danger">
993+
* **Note**: {@link $compile#-replace- `replace: true`} is deprecated and not recommended to use,
994+
* mainly due to the issues listed here. It has been completely removed in the new Angular.
995+
* </div>
996+
*
997+
* #### Attribute values are not merged
998+
*
999+
* When a `replace` directive encounters the same attribute on the original and the replace node,
1000+
* it will simply deduplicate the attribute and join the values with a space or with a `;` in case of
1001+
* the `style` attribute.
1002+
* ```html
1003+
* Original Node: <span class="original" style="color: red;"></span>
1004+
* Replace Template: <span class="replaced" style="background: blue;"></span>
1005+
* Result: <span class="original replaced" style="color: red; background: blue;"></span>
1006+
* ```
1007+
*
1008+
* That means attributes that contain AngularJS expressions will not be merged correctly, e.g.
1009+
* {@link ngShow} or {@link ngClass} will cause a {@link $parse} error:
1010+
*
1011+
* ```html
1012+
* Original Node: <span ng-class="{'something': something}" ng-show="!condition"></span>
1013+
* Replace Template: <span ng-class="{'else': else}" ng-show="otherCondition"></span>
1014+
* Result: <span ng-class="{'something': something} {'else': else}" ng-show="!condition otherCondition"></span>
1015+
* ```
1016+
*
1017+
* See issue [#5695](https://github.com/angular/angular.js/issues/5695).
1018+
*
1019+
* #### Directives are not deduplicated before compilation
1020+
*
1021+
* When the original node and the replace template declare the same directive(s), they will be
1022+
* {@link guide/compiler#double-compilation-and-how-to-avoid-it compiled twice} because the compiler
1023+
* does not deduplicate them. In many cases, this is not noticable, but e.g. {@link ngModel} will
1024+
* attach `$formatters` and `$parsers` twice.
1025+
*
1026+
* See issue [#2573](https://github.com/angular/angular.js/issues/2573).
1027+
*
1028+
* #### `transclude: element` in the replace template root can have
1029+
* unexpected effects
1030+
*
1031+
* When the replace template has a directive at the root node that uses
1032+
* {@link $compile#-transclude- `transclude: element`}, e.g.
1033+
* {@link ngIf} or {@link ngRepeat}, the DOM structure or scope inheritance can be incorrect.
1034+
* See the following issues:
1035+
*
1036+
* - Incorrect scope on replaced element:
1037+
* [#9837](https://github.com/angular/angular.js/issues/9837)
1038+
* - Different DOM between `template` and `templateUrl`:
1039+
* [#10612](https://github.com/angular/angular.js/issues/14326)
9861040
*
9871041
*/
9881042

0 commit comments

Comments
 (0)