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

Commit 31ea071

Browse files
committed
docs($compile): add known issues with replace:true
Closes #16523 Related #2573 Related #5695 Related #9837 Related #10612
1 parent abe6acf commit 31ea071

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
@@ -506,9 +506,10 @@
506506
* $sce#getTrustedResourceUrl $sce.getTrustedResourceUrl}.
507507
*
508508
*
509-
* #### `replace` (*DEPRECATED*)
510-
*
511-
* `replace` will be removed in next major release - i.e. v2.0).
509+
* #### `replace`
510+
* <div class="alert alert-danger">
511+
* **Note:** `replace` is deprecated in AngularJS and has been removed in the new Angular (v2+).
512+
* </div>
512513
*
513514
* Specifies what the template should replace. Defaults to `false`.
514515
*
@@ -958,6 +959,59 @@
958959
compiled again. This is an undesired effect and can lead to misbehaving directives, performance issues,
959960
and memory leaks. Refer to the Compiler Guide {@link guide/compiler#double-compilation-and-how-to-avoid-it
960961
section on double compilation} for an in-depth explanation and ways to avoid it.
962+
963+
* @knownIssue
964+
965+
### Issues with `replace: true`
966+
*
967+
* <div class="alert alert-danger">
968+
* **Note**: {@link $compile#-replace- `replace: true`} is deprecated and not recommended to use,
969+
* mainly due to the issues listed here. It has been completely removed in the new Angular.
970+
* </div>
971+
*
972+
* #### Attribute values are not merged
973+
*
974+
* When a `replace` directive encounters the same attribute on the original and the replace node,
975+
* it will simply deduplicate the attribute and join the values with a space or with a `;` in case of
976+
* the `style` attribute.
977+
* ```html
978+
* Original Node: <span class="original" style="color: red;"></span>
979+
* Replace Template: <span class="replaced" style="background: blue;"></span>
980+
* Result: <span class="original replaced" style="color: red; background: blue;"></span>
981+
* ```
982+
*
983+
* That means attributes that contain AngularJS expressions will not be merged correctly, e.g.
984+
* {@link ngShow} or {@link ngClass} will cause a {@link $parse} error:
985+
*
986+
* ```html
987+
* Original Node: <span ng-class="{'something': something}" ng-show="!condition"></span>
988+
* Replace Template: <span ng-class="{'else': else}" ng-show="otherCondition"></span>
989+
* Result: <span ng-class="{'something': something} {'else': else}" ng-show="!condition otherCondition"></span>
990+
* ```
991+
*
992+
* See issue [#5695](https://github.com/angular/angular.js/issues/5695).
993+
*
994+
* #### Directives are not deduplicated before compilation
995+
*
996+
* When the original node and the replace template declare the same directive(s), they will be
997+
* {@link guide/compiler#double-compilation-and-how-to-avoid-it compiled twice} because the compiler
998+
* does not deduplicate them. In many cases, this is not noticable, but e.g. {@link ngModel} will
999+
* attach `$formatters` and `$parsers` twice.
1000+
*
1001+
* See issue [#2573](https://github.com/angular/angular.js/issues/2573).
1002+
*
1003+
* #### `transclude: element` in the replace template root can have
1004+
* unexpected effects
1005+
*
1006+
* When the replace template has a directive at the root node that uses
1007+
* {@link $compile#-transclude- `transclude: element`}, e.g.
1008+
* {@link ngIf} or {@link ngRepeat}, the DOM structure or scope inheritance can be incorrect.
1009+
* See the following issues:
1010+
*
1011+
* - Incorrect scope on replaced element:
1012+
* [#9837](https://github.com/angular/angular.js/issues/9837)
1013+
* - Different DOM between `template` and `templateUrl`:
1014+
* [#10612](https://github.com/angular/angular.js/issues/14326)
9611015
*
9621016
*/
9631017

0 commit comments

Comments
 (0)